Support requirements on standard input
Allow a --file parameter of "-" to indicate the package list is read on standard input, to support use in a traditional command pipeline. Change-Id: Ic6e54af185e4b07825fcde3ef991f53de0a9ecfa
This commit is contained in:
parent
decf073166
commit
4db1a7a057
|
@ -18,6 +18,10 @@ dependencies. Users without `bindep` installed can consult the
|
||||||
``other-requirements.txt`` file by hand if they choose, or install `bindep`
|
``other-requirements.txt`` file by hand if they choose, or install `bindep`
|
||||||
first and then use it.
|
first and then use it.
|
||||||
|
|
||||||
|
If you need to maintain multiple requirements list files you can pass a
|
||||||
|
specific filename with the -f/--file command line option. If you want to read
|
||||||
|
the list from standard input in a pipeline instead, use a filename of "-".
|
||||||
|
|
||||||
Profiles
|
Profiles
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
|
|
@ -40,12 +40,15 @@ 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:
|
||||||
try:
|
if opts.filename == "-":
|
||||||
content = open(opts.filename, 'rt').read()
|
fd = sys.stdin
|
||||||
except IOError:
|
else:
|
||||||
logging.error('No %s file found.' % opts.filename)
|
try:
|
||||||
return 1
|
fd = open(opts.filename, 'rt')
|
||||||
depends = bindep.depends.Depends(content)
|
except IOError:
|
||||||
|
logging.error('No %s file found.' % opts.filename)
|
||||||
|
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():
|
||||||
|
|
|
@ -100,6 +100,12 @@ class TestMain(TestCase):
|
||||||
'No alternative-requirements.txt file found.\n',
|
'No alternative-requirements.txt file found.\n',
|
||||||
fixture.logger.output)
|
fixture.logger.output)
|
||||||
|
|
||||||
|
def test_stdin_requirements_file(self):
|
||||||
|
fixture = self.useFixture(MainFixture())
|
||||||
|
self.useFixture(MonkeyPatch('sys.argv', ['bindep', '--file', '-']))
|
||||||
|
self.assertEqual(0, main())
|
||||||
|
self.assertEqual('', fixture.logger.output)
|
||||||
|
|
||||||
def test_specific_profile(self):
|
def test_specific_profile(self):
|
||||||
logger = self.useFixture(FakeLogger())
|
logger = self.useFixture(FakeLogger())
|
||||||
self.useFixture(MonkeyPatch('sys.argv', ['bindep', 'myprofile']))
|
self.useFixture(MonkeyPatch('sys.argv', ['bindep', 'myprofile']))
|
||||||
|
|
Loading…
Reference in New Issue