3699: more help text for --src and --dst options
[arvados.git] / sdk / python / bin / arv-get
index c1b2bcbaf5a0dcb0ae2914eb7c145a31fab3efaa..0d403d103668528ba780b6c084d6601b8b5928c3 100755 (executable)
@@ -31,8 +31,10 @@ group = parser.add_mutually_exclusive_group()
 group.add_argument('--progress', action='store_true',
                    help="""
 Display human-readable progress on stderr (bytes and, if possible,
-percentage of total data size). This is the default behavior when
-stderr is a tty and stdout is not a tty.
+percentage of total data size). This is the default behavior when it
+is not expected to interfere with the output: specifically, stderr is
+a tty _and_ either stdout is not a tty, or output is being written to
+named files rather than stdout.
 """)
 group.add_argument('--no-progress', action='store_true',
                    help="""
@@ -96,12 +98,6 @@ if not args.r and (os.path.isdir(args.destination) or
     logger.debug("Appended source file name to destination directory: %s",
                  args.destination)
 
-# Turn on --progress by default if stderr is a tty and stdout isn't.
-if (not (args.batch_progress or args.no_progress)
-    and os.isatty(sys.stderr.fileno())
-    and not os.isatty(sys.stdout.fileno())):
-    args.progress = True
-
 if args.destination == '-':
     args.destination = '/dev/stdout'
 if args.destination == '/dev/stdout':
@@ -112,6 +108,15 @@ if args.destination == '/dev/stdout':
 else:
     args.destination = args.destination.rstrip(os.sep)
 
+# Turn on --progress by default if stderr is a tty and output is
+# either going to a named file, or going (via stdout) to something
+# that isn't a tty.
+if (not (args.batch_progress or args.no_progress)
+    and sys.stderr.isatty()
+    and (args.destination != '/dev/stdout'
+         or not sys.stdout.isatty())):
+    args.progress = True
+
 
 r = re.search(r'^(.*?)(/.*)?$', args.locator)
 collection = r.group(1)
@@ -121,6 +126,7 @@ if args.r and not get_prefix:
 
 todo = []
 todo_bytes = 0
+api_client = arvados.api('v1')
 if not get_prefix:
     try:
         if not args.n:
@@ -128,15 +134,15 @@ if not get_prefix:
                 abort('Local file %s already exists.' % (args.destination,))
             with open(args.destination, 'wb') as f:
                 try:
-                    c = arvados.api('v1').collections().get(
-                        uuid=collection).execute()
+                    c = api_client.collections().get(uuid=collection).execute()
                     manifest = c['manifest_text']
                 except Exception as e:
                     logger.warning(
                         "Collection %s not found. " +
                         "Trying to fetch directly from Keep (deprecated).",
                         collection)
-                    manifest = arvados.Keep.get(collection)
+                    manifest = arvados.KeepClient(
+                        api_client=api_client).get(collection)
                 f.write(manifest)
         sys.exit(0)
     except arvados.errors.NotFoundError as e: