Browse code

Allow stdout as destination when receiving multiple remote files

- special case stdout when enforcing destination rules
- update parameter error output to indicate stdout is a valid destination specification

robwills authored on 2011/07/10 04:18:04
Showing 1 changed files
... ...
@@ -336,6 +336,7 @@ def cmd_object_get(args):
336 336
     ##       - apply exclude/include rules
337 337
     ##       - each list item will have MD5sum, Timestamp and pointer to S3Uri
338 338
     ##         used as a prefix.
339
+    ##   - the last arg may be '-' (stdout)
339 340
     ##   - the last arg may be a local directory - destination_base
340 341
     ##   - if the last one is S3 make current dir the destination_base
341 342
     ##   - if the last one doesn't exist check remote list:
... ...
@@ -369,10 +370,14 @@ def cmd_object_get(args):
369 369
     info(u"Summary: %d remote files to download" % remote_count)
370 370
 
371 371
     if remote_count > 0:
372
-        if not os.path.isdir(destination_base) or destination_base == '-':
373
-            ## We were either given a file name (existing or not) or want STDOUT
372
+        if destination_base == "-":
373
+            ## stdout is ok for multiple remote files!
374
+            for key in remote_list:
375
+                remote_list[key]['local_filename'] = "-"
376
+        elif not os.path.isdir(destination_base):
377
+            ## We were either given a file name (existing or not)
374 378
             if remote_count > 1:
375
-                raise ParameterError("Destination must be a directory when downloading multiple sources.")
379
+                raise ParameterError("Destination must be a directory or stdout when downloading multiple sources.")
376 380
             remote_list[remote_list.keys()[0]]['local_filename'] = deunicodise(destination_base)
377 381
         elif os.path.isdir(destination_base):
378 382
             if destination_base[-1] != os.path.sep: