Browse code

Modify command equivalent to a self copy to modify metadata

Francois Gaudin authored on 2012/12/07 04:29:32
Showing 1 changed files
... ...
@@ -489,9 +489,15 @@ def subcmd_object_del_uri(uri_str, recursive = None):
489 489
         output(u"File %s deleted" % item['object_uri_str'])
490 490
 
491 491
 def subcmd_cp_mv(args, process_fce, action_str, message):
492
-    if len(args) < 2:
492
+    if action_str != 'modify' and len(args) < 2:
493 493
         raise ParameterError("Expecting two or more S3 URIs for " + action_str)
494
-    dst_base_uri = S3Uri(args.pop())
494
+    if action_str == 'modify' and len(args) < 1:
495
+        raise ParameterError("Expecting one or more S3 URIs for " + action_str)
496
+    if action_str != 'modify':
497
+        dst_base_uri = S3Uri(args.pop())
498
+    else:
499
+        dst_base_uri = S3Uri(args[-1])
500
+
495 501
     if dst_base_uri.type != "s3":
496 502
         raise ParameterError("Destination must be S3 URI. To download a file use 'get' or 'sync'.")
497 503
     destination_base = dst_base_uri.uri()
... ...
@@ -543,6 +549,10 @@ def cmd_cp(args):
543 543
     s3 = S3(Config())
544 544
     subcmd_cp_mv(args, s3.object_copy, "copy", "File %(src)s copied to %(dst)s")
545 545
 
546
+def cmd_modify(args):
547
+    s3 = S3(Config())
548
+    subcmd_cp_mv(args, s3.object_copy, "modify", "File %(src)s modified")
549
+
546 550
 def cmd_mv(args):
547 551
     s3 = S3(Config())
548 552
     subcmd_cp_mv(args, s3.object_move, "move", "File %(src)s moved to %(dst)s")
... ...
@@ -1390,6 +1400,7 @@ def get_commands_list():
1390 1390
     {"cmd":"du", "label":"Disk usage by buckets", "param":"[s3://BUCKET[/PREFIX]]", "func":cmd_du, "argc":0},
1391 1391
     {"cmd":"info", "label":"Get various information about Buckets or Files", "param":"s3://BUCKET[/OBJECT]", "func":cmd_info, "argc":1},
1392 1392
     {"cmd":"cp", "label":"Copy object", "param":"s3://BUCKET1/OBJECT1 s3://BUCKET2[/OBJECT2]", "func":cmd_cp, "argc":2},
1393
+    {"cmd":"modify", "label":"Modify object metadata", "param":"s3://BUCKET1/OBJECT", "func":cmd_modify, "argc":1},
1393 1394
     {"cmd":"mv", "label":"Move object", "param":"s3://BUCKET1/OBJECT1 s3://BUCKET2[/OBJECT2]", "func":cmd_mv, "argc":2},
1394 1395
     {"cmd":"setacl", "label":"Modify Access control list for Bucket or Files", "param":"s3://BUCKET[/OBJECT]", "func":cmd_setacl, "argc":1},
1395 1396
     {"cmd":"accesslog", "label":"Enable/disable bucket access logging", "param":"s3://BUCKET", "func":cmd_accesslog, "argc":1},