Merge "Extract file finding and processing to functions"
This commit is contained in:
commit
4a96f38637
|
@ -15,8 +15,11 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import os.path
|
||||||
from parsley import makeGrammar
|
from parsley import makeGrammar
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
debversion_grammar = """
|
debversion_grammar = """
|
||||||
|
@ -53,6 +56,50 @@ blank = ws? '\n' -> None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def get_depends(filename=None):
|
||||||
|
fd = get_depends_file(filename)
|
||||||
|
if not fd:
|
||||||
|
return None
|
||||||
|
return Depends(fd.read())
|
||||||
|
|
||||||
|
|
||||||
|
def get_depends_file(filename=None):
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
if filename == "-":
|
||||||
|
return sys.stdin
|
||||||
|
elif filename:
|
||||||
|
try:
|
||||||
|
fd = open(filename, 'rt')
|
||||||
|
except IOError:
|
||||||
|
log.error('Error reading file %s.' % filename)
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
if (os.path.isfile('bindep.txt') and
|
||||||
|
os.path.isfile('other-requirements.txt')):
|
||||||
|
log.error(
|
||||||
|
'Both bindep.txt and other-requirements.txt '
|
||||||
|
'files exist, choose one.')
|
||||||
|
return None
|
||||||
|
if os.path.isfile('bindep.txt'):
|
||||||
|
try:
|
||||||
|
fd = open('bindep.txt', 'rt')
|
||||||
|
except IOError:
|
||||||
|
log.error('Error reading file bindep.txt.')
|
||||||
|
return None
|
||||||
|
elif os.path.isfile('other-requirements.txt'):
|
||||||
|
try:
|
||||||
|
fd = open('other-requirements.txt', 'rt')
|
||||||
|
except IOError:
|
||||||
|
log.error('Error reading file other-requirements.txt.')
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
log.error(
|
||||||
|
'Neither file bindep.txt nor file '
|
||||||
|
'other-requirements.txt exist.')
|
||||||
|
return None
|
||||||
|
return fd
|
||||||
|
|
||||||
|
|
||||||
class Depends(object):
|
class Depends(object):
|
||||||
"""Project dependencies."""
|
"""Project dependencies."""
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import optparse
|
import optparse
|
||||||
import os.path
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import bindep.depends
|
import bindep.depends
|
||||||
|
@ -44,38 +43,9 @@ def main(depends=None):
|
||||||
help="List the platform and configuration profiles.")
|
help="List the platform and configuration profiles.")
|
||||||
opts, args = parser.parse_args()
|
opts, args = parser.parse_args()
|
||||||
if depends is None:
|
if depends is None:
|
||||||
if opts.filename == "-":
|
depends = bindep.depends.get_depends(opts.filename)
|
||||||
fd = sys.stdin
|
if not depends:
|
||||||
elif opts.filename:
|
return 1
|
||||||
try:
|
|
||||||
fd = open(opts.filename, 'rt')
|
|
||||||
except IOError:
|
|
||||||
logging.error('Error reading file %s.' % opts.filename)
|
|
||||||
return 1
|
|
||||||
else:
|
|
||||||
if (os.path.isfile('bindep.txt') and
|
|
||||||
os.path.isfile('other-requirements.txt')):
|
|
||||||
logging.error('Both bindep.txt and other-requirements.txt '
|
|
||||||
'files exist, choose one.')
|
|
||||||
return 1
|
|
||||||
if os.path.isfile('bindep.txt'):
|
|
||||||
try:
|
|
||||||
fd = open('bindep.txt', 'rt')
|
|
||||||
except IOError:
|
|
||||||
logging.error('Error reading file bindep.txt.')
|
|
||||||
return 1
|
|
||||||
elif os.path.isfile('other-requirements.txt'):
|
|
||||||
try:
|
|
||||||
fd = open('other-requirements.txt', 'rt')
|
|
||||||
except IOError:
|
|
||||||
logging.error('Error reading file other-requirements.txt.')
|
|
||||||
return 1
|
|
||||||
else:
|
|
||||||
logging.error('Neither file bindep.txt nor file '
|
|
||||||
'other-requirements.txt exist.')
|
|
||||||
return 1
|
|
||||||
|
|
||||||
depends = bindep.depends.Depends(fd.read())
|
|
||||||
if opts.profiles:
|
if opts.profiles:
|
||||||
logging.info("Platform profiles:")
|
logging.info("Platform profiles:")
|
||||||
for profile in depends.platform_profiles():
|
for profile in depends.platform_profiles():
|
||||||
|
|
Loading…
Reference in New Issue