Skip to content
This repository has been archived by the owner on Nov 4, 2018. It is now read-only.

Commit

Permalink
Allow stdout as destination when receiving multiple remote files
Browse files Browse the repository at this point in the history
- special case stdout when enforcing destination rules
- update parameter error output to indicate stdout is a valid destination specification
  • Loading branch information
ohhorob committed Jul 9, 2011
1 parent bcb4442 commit 2320b45
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions s3cmd
Expand Up @@ -336,6 +336,7 @@ def cmd_object_get(args):
## - apply exclude/include rules ## - apply exclude/include rules
## - each list item will have MD5sum, Timestamp and pointer to S3Uri ## - each list item will have MD5sum, Timestamp and pointer to S3Uri
## used as a prefix. ## used as a prefix.
## - the last arg may be '-' (stdout)
## - the last arg may be a local directory - destination_base ## - the last arg may be a local directory - destination_base
## - if the last one is S3 make current dir the destination_base ## - if the last one is S3 make current dir the destination_base
## - if the last one doesn't exist check remote list: ## - if the last one doesn't exist check remote list:
Expand Down Expand Up @@ -369,10 +370,14 @@ def cmd_object_get(args):
info(u"Summary: %d remote files to download" % remote_count) info(u"Summary: %d remote files to download" % remote_count)


if remote_count > 0: if remote_count > 0:
if not os.path.isdir(destination_base) or destination_base == '-': if destination_base == "-":
## We were either given a file name (existing or not) or want STDOUT ## stdout is ok for multiple remote files!
for key in remote_list:
remote_list[key]['local_filename'] = "-"
elif not os.path.isdir(destination_base):
## We were either given a file name (existing or not)
if remote_count > 1: if remote_count > 1:
raise ParameterError("Destination must be a directory when downloading multiple sources.") raise ParameterError("Destination must be a directory or stdout when downloading multiple sources.")
remote_list[remote_list.keys()[0]]['local_filename'] = deunicodise(destination_base) remote_list[remote_list.keys()[0]]['local_filename'] = deunicodise(destination_base)
elif os.path.isdir(destination_base): elif os.path.isdir(destination_base):
if destination_base[-1] != os.path.sep: if destination_base[-1] != os.path.sep:
Expand Down

0 comments on commit 2320b45

Please sign in to comment.