Improve compatibility with whput.
authorTom Clegg <tom@clinicalfuture.com>
Tue, 3 Dec 2013 08:27:35 +0000 (00:27 -0800)
committerTom Clegg <tom@clinicalfuture.com>
Tue, 3 Dec 2013 08:27:35 +0000 (00:27 -0800)
* Default to --raw when operating on a single file or stdin
* Accept --use-filename for --filename
* Accept --in-manifest for --manifest
* In --raw mode use comma instead of space between locators

refs #1646

sdk/cli/bin/arv-put
sdk/cli/test/test_arv-put.rb

index bbd6d032103deb9306995bbf8a256cc038b447ae..e6421fbfcc5e993e2efac6d3a2bc1fb7e06028b4 100755 (executable)
@@ -36,11 +36,17 @@ group.add_argument('--as-manifest', action='store_true', dest='manifest',
                    help="""
 Synonym for --manifest.
 """)
+group.add_argument('--in-manifest', action='store_true', dest='manifest',
+                   help="""
+Synonym for --manifest.
+""")
 group.add_argument('--manifest', action='store_true',
                    help="""
 Store the file data and resulting manifest in Keep, save a Collection
 object in Arvados, and display the manifest locator (Collection uuid)
-on stdout. This is the default behavior.
+on stdout. This is the default behavior if more than one path argument
+is given, or the path given is a directory, or a --filename argument
+is given.
 """)
 group.add_argument('--as-raw', action='store_true', dest='raw',
                    help="""
@@ -49,14 +55,20 @@ Synonym for --raw.
 group.add_argument('--raw', action='store_true',
                    help="""
 Store the file content and display the data block locators on stdout,
-separated by spaces, with a trailing newline. Do not store a manifest.
+separated by spaces, with a trailing newline. Do not store a
+manifest. This is the default behavior when reading data from a single
+file or standard input.
+""")
+parser.add_argument('--use-filename', type=str, default=None, dest='filename',
+                    help="""
+Synonym for --filename.
 """)
 parser.add_argument('--filename', type=str, default=None,
                     help="""
 Use the given filename in the manifest, instead of the name of the
 local file. This is useful when "-" or "/dev/stdin" is given as an
 input file. It can be used only if there is exactly one path given and
-it is not a directory.
+it is not a directory. Implies --manifest.
 """)
 group = parser.add_mutually_exclusive_group()
 group.add_argument('--progress', action='store_true',
@@ -81,11 +93,16 @@ args = parser.parse_args()
 if len(args.paths) == 0:
     args.paths += ['/dev/stdin']
 
-if args.filename and (len(args.paths) != 1 or os.path.isdir(args.paths[0])):
-    parser.error("""
+if len(args.paths) != 1 or os.path.isdir(args.paths[0]):
+    if args.filename:
+        parser.error("""
 --filename argument cannot be used when storing a directory or
 multiple files.
 """)
+elif not args.filename and not args.stream and not args.manifest:
+    # When reading from a single non-directory, and no --filename is
+    # given, default to writing raw blocks rather than a manifest.
+    args.raw = True
 
 # Turn on --progress by default if stderr is a tty.
 if (not (args.batch_progress or args.no_progress)
@@ -172,7 +189,7 @@ if args.stream:
     print writer.manifest_text(),
 elif args.raw:
     writer.finish_current_stream()
-    print string.join(writer.data_locators(), ' ') + '\n'
+    print string.join(writer.data_locators(), ',') + '\n'
 else:
     # Register the resulting collection in Arvados.
     arvados.api().collections().create(
index de619b9d92280339a23e4edb5c7f1cb4fa9de4a8..5efbfda8298ec03b8dcd1e89ec27bea16ae4798d 100644 (file)
@@ -65,7 +65,7 @@ class TestArvPut < Minitest::Test
 
   def test_progress
     out, err = capture_subprocess_io do
-      assert_equal true, arv_put('--progress', './tmp/foo')
+      assert_equal true, arv_put('--manifest', '--progress', './tmp/foo')
     end
     assert_match /%/, err
     assert_equal foo_manifest_locator+"\n", out
@@ -73,7 +73,7 @@ class TestArvPut < Minitest::Test
 
   def test_batch_progress
     out, err = capture_subprocess_io do
-      assert_equal true, arv_put('--batch-progress', './tmp/foo')
+      assert_equal true, arv_put('--manifest', '--batch-progress', './tmp/foo')
     end
     assert_match /: 0 written 3 total/, err
     assert_match /: 3 written 3 total/, err