git-svn-id: https://s3tools.svn.sourceforge.net/svnroot/s3tools/s3cmd/trunk@353 830e0280-6d2a-0410-9c65-932aecc39d9d
Michal Ludvig authored on 2009/01/24 20:24:43... | ... |
@@ -261,16 +261,12 @@ def cmd_object_put(args): |
261 | 261 |
cfg = Config() |
262 | 262 |
s3 = S3(cfg) |
263 | 263 |
|
264 |
- ## Each item will be a dict with the following attributes |
|
265 |
- # {'remote_uri', 'local_filename'} |
|
266 |
- upload_list = [] |
|
267 |
- |
|
268 | 264 |
if len(args) == 0: |
269 |
- raise ParameterError("Nothing to upload. Expecting a local file or directory.") |
|
265 |
+ raise ParameterError("Nothing to upload. Expecting a local file or directory and a S3 URI destination.") |
|
270 | 266 |
|
271 |
- dst_uri = S3Uri(args.pop()) |
|
272 |
- if dst_uri.type != 's3': |
|
273 |
- raise ParameterError("Destination must be S3Uri. Got: %s" % args[-1]) |
|
267 |
+ destination_base = args.pop() |
|
268 |
+ if S3Uri(destination_base).type != 's3': |
|
269 |
+ raise ParameterError("Destination must be S3Uri. Got: %s" % destination_base) |
|
274 | 270 |
|
275 | 271 |
if len(args) == 0: |
276 | 272 |
raise ParameterError("Nothing to upload. Expecting a local file or directory.") |
... | ... |
@@ -278,19 +274,30 @@ def cmd_object_put(args): |
278 | 278 |
local_list = fetch_local_list(args) |
279 | 279 |
local_count = len(local_list) |
280 | 280 |
|
281 |
- if local_count > 1 and not dst_uri.object() == "" and not dst_uri.object().endswith("/"): |
|
282 |
- raise ParameterError(u"When uploading multiple files the last argument must be a S3 URI ending with '/' or a bucket name only!") |
|
281 |
+ local_list, exclude_list = _filelist_filter_exclude_include(local_list) |
|
282 |
+ |
|
283 |
+ if not destination_base.endswith("/"): |
|
284 |
+ if local_count > 1: |
|
285 |
+ raise ParameterError("Destination S3 URI must end with '/' (ie must refer to a directory on the remote side).") |
|
286 |
+ local_list[local_list.keys()[0]]['remote_uri'] = unicodise(destination_base) |
|
287 |
+ else: |
|
288 |
+ for key in local_list: |
|
289 |
+ local_list[key]['remote_uri'] = unicodise(destination_base + key) |
|
290 |
+ |
|
291 |
+ if cfg.dry_run: |
|
292 |
+ for key in exclude_list: |
|
293 |
+ output(u"exclude: %s" % unicodise(key)) |
|
294 |
+ for key in local_list: |
|
295 |
+ output(u"upload: %s -> %s" % (local_list[key]['full_name_unicode'], local_list[key]['remote_uri'])) |
|
296 |
+ |
|
297 |
+ warning(u"Exitting now because of --dry-run") |
|
298 |
+ return |
|
283 | 299 |
|
284 |
- sorted_local_keys = local_list.keys() |
|
285 |
- sorted_local_keys.sort() |
|
286 | 300 |
seq = 0 |
287 |
- for key in sorted_local_keys: |
|
301 |
+ for key in local_list: |
|
288 | 302 |
seq += 1 |
289 | 303 |
|
290 |
- if local_count > 1 or dst_uri.object() == "": |
|
291 |
- uri_final = S3Uri(u"%s%s" % (dst_uri, key)) |
|
292 |
- else: |
|
293 |
- uri_final = dst_uri |
|
304 |
+ uri_final = S3Uri(local_list[key]['remote_uri']) |
|
294 | 305 |
|
295 | 306 |
extra_headers = {} |
296 | 307 |
full_name_orig = local_list[key]['full_name'] |
... | ... |
@@ -367,6 +374,8 @@ def cmd_object_get(args): |
367 | 367 |
remote_list = fetch_remote_list(args, require_attribs = False) |
368 | 368 |
remote_count = len(remote_list) |
369 | 369 |
|
370 |
+ remote_list, exclude_list = _filelist_filter_exclude_include(remote_list) |
|
371 |
+ |
|
370 | 372 |
if not os.path.isdir(destination_base) or destination_base == '-': |
371 | 373 |
## We were either given a file name (existing or not) or want STDOUT |
372 | 374 |
if remote_count > 1: |
... | ... |
@@ -380,6 +389,15 @@ def cmd_object_get(args): |
380 | 380 |
else: |
381 | 381 |
raise InternalError("WTF? Is it a dir or not? -- %s" % destination_base) |
382 | 382 |
|
383 |
+ if cfg.dry_run: |
|
384 |
+ for key in exclude_list: |
|
385 |
+ output(u"exclude: %s" % unicodise(key)) |
|
386 |
+ for key in remote_list: |
|
387 |
+ output(u"download: %s -> %s" % (remote_list[key]['object_uri_str'], remote_list[key]['local_filename'])) |
|
388 |
+ |
|
389 |
+ warning(u"Exitting now because of --dry-run") |
|
390 |
+ return |
|
391 |
+ |
|
383 | 392 |
seq = 0 |
384 | 393 |
for key in remote_list: |
385 | 394 |
seq += 1 |
... | ... |
@@ -733,7 +751,7 @@ def cmd_sync_remote2local(args): |
733 | 733 |
|
734 | 734 |
if cfg.dry_run: |
735 | 735 |
for key in exclude_list: |
736 |
- output(u"excluded: %s" % unicodise(key)) |
|
736 |
+ output(u"exclude: %s" % unicodise(key)) |
|
737 | 737 |
for key in local_list: |
738 | 738 |
output(u"delete: %s" % local_list[key]['full_name_unicode']) |
739 | 739 |
for key in remote_list: |
... | ... |
@@ -898,9 +916,9 @@ def cmd_sync_local2remote(args): |
898 | 898 |
|
899 | 899 |
if cfg.dry_run: |
900 | 900 |
for key in exclude_list: |
901 |
- output(u"excluded: %s" % unicodise(key)) |
|
901 |
+ output(u"exclude: %s" % unicodise(key)) |
|
902 | 902 |
for key in remote_list: |
903 |
- output(u"deleted: %s" % remote_list[key]['object_uri_str']) |
|
903 |
+ output(u"delete: %s" % remote_list[key]['object_uri_str']) |
|
904 | 904 |
for key in local_list: |
905 | 905 |
output(u"upload: %s -> %s" % (local_list[key]['full_name_unicode'], local_list[key]['remote_uri'])) |
906 | 906 |
|