2879: arv-put main() returns what it prints.
authorBrett Smith <brett@curoverse.com>
Tue, 10 Jun 2014 15:09:42 +0000 (11:09 -0400)
committerBrett Smith <brett@curoverse.com>
Thu, 12 Jun 2014 19:40:16 +0000 (15:40 -0400)
This will enable other tools to reuse the results.

sdk/python/arvados/commands/put.py
sdk/python/tests/test_arv_put.py

index e4e1b6dad28447b8300cca524a9c66cefd592a45..ef34e071992373ab783cd33baad23a4bbfa3c991 100644 (file)
@@ -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()
index b7c6ed6892ea4098db4b2fd89a247d6546c5b5a6..4687b4e0b6d1a837dcec593f5434c804f7ba0ded 100644 (file)
@@ -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')),