From af6ef4aefe653ac5fd7bbd028af580ddfeb8f4d9 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Tue, 10 Jun 2014 11:09:42 -0400 Subject: [PATCH] 2879: arv-put main() returns what it prints. This will enable other tools to reuse the results. --- sdk/python/arvados/commands/put.py | 17 ++++++++++++----- sdk/python/tests/test_arv_put.py | 5 ++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/sdk/python/arvados/commands/put.py b/sdk/python/arvados/commands/put.py index e4e1b6dad2..ef34e07199 100644 --- a/sdk/python/arvados/commands/put.py +++ b/sdk/python/arvados/commands/put.py @@ -328,7 +328,7 @@ def progress_writer(progress_func, outfile=sys.stderr): def exit_signal_handler(sigcode, frame): sys.exit(-sigcode) -def main(arguments=None): +def main(arguments=None, output_to=sys.stdout): args = parse_arguments(arguments) if args.progress: @@ -346,7 +346,8 @@ def main(arguments=None): except (IOError, OSError): pass # Couldn't open cache directory/file. Continue without it. except ResumeCacheConflict: - print "arv-put: Another process is already uploading this data." + output_to.write( + "arv-put: Another process is already uploading this data.\n") sys.exit(1) if resume_cache is None: @@ -382,9 +383,9 @@ def main(arguments=None): print >>sys.stderr if args.stream: - print writer.manifest_text(), + output = writer.manifest_text() elif args.raw: - print ','.join(writer.data_locators()) + output = ','.join(writer.data_locators()) else: # Register the resulting collection in Arvados. collection = arvados.api().collections().create( @@ -395,7 +396,11 @@ def main(arguments=None): ).execute() # Print the locator (uuid) of the new collection. - print collection['uuid'] + output = collection['uuid'] + + output_to.write(output) + if not output.endswith('\n'): + output_to.write('\n') for sigcode, orig_handler in orig_signal_handlers.items(): signal.signal(sigcode, orig_handler) @@ -403,5 +408,7 @@ def main(arguments=None): if resume_cache is not None: resume_cache.destroy() + return output + if __name__ == '__main__': main() diff --git a/sdk/python/tests/test_arv_put.py b/sdk/python/tests/test_arv_put.py index b7c6ed6892..4687b4e0b6 100644 --- a/sdk/python/tests/test_arv_put.py +++ b/sdk/python/tests/test_arv_put.py @@ -12,6 +12,8 @@ import time import unittest import yaml +from cStringIO import StringIO + import arvados import arvados.commands.put as arv_put @@ -323,9 +325,10 @@ class ArvadosPutReportTest(ArvadosBaseTestCase): class ArvadosPutTest(ArvadosKeepLocalStoreTestCase): def call_main_on_test_file(self): + self.main_output = StringIO() with self.make_test_file() as testfile: path = testfile.name - arv_put.main(['--stream', '--no-progress', path]) + arv_put.main(['--stream', '--no-progress', path], self.main_output) self.assertTrue( os.path.exists(os.path.join(os.environ['KEEP_LOCAL_STORE'], '098f6bcd4621d373cade4e832627b4f6')), -- 2.30.2