Browse code

* s3cmd: Enable bucket-level ACL setting

git-svn-id: https://s3tools.svn.sourceforge.net/svnroot/s3tools/s3cmd/trunk@404 830e0280-6d2a-0410-9c65-932aecc39d9d

Michal Ludvig authored on 2010/03/19 13:16:01
Showing 2 changed files
... ...
@@ -1,5 +1,6 @@
1 1
 2010-03-19  Michal Ludvig  <mludvig@logix.net.nz>
2 2
 
3
+	* s3cmd: Enable bucket-level ACL setting
3 4
 	* s3cmd, S3/AccessLog.py, ...: Added [accesslog] command.
4 5
 	* s3cmd: Fix imports from S3.Utils
5 6
 
... ...
@@ -1081,10 +1081,39 @@ def cmd_sync(args):
1081 1081
 	raise ParameterError("Invalid source/destination: '%s'" % "' '".join(args))
1082 1082
 
1083 1083
 def cmd_setacl(args):
1084
+	def _update_acl(uri, seq_label = ""):
1085
+		acl = s3.get_acl(uri)
1086
+		debug(u"acl: %s - %r" % (uri, acl.grantees))
1087
+		if cfg.acl_public:
1088
+			if acl.isAnonRead():
1089
+				info(u"%s: already Public, skipping %s" % (uri, seq_label))
1090
+				return
1091
+			acl.grantAnonRead()
1092
+		else:
1093
+			if not acl.isAnonRead():
1094
+				info(u"%s: already Private, skipping %s" % (uri, seq_label))
1095
+				return
1096
+			acl.revokeAnonRead()
1097
+		retsponse = s3.set_acl(uri, acl)
1098
+		if retsponse['status'] == 200:
1099
+			output(u"%s: ACL set to %s  %s" % (uri, set_to_acl, seq_label))
1100
+
1084 1101
 	s3 = S3(cfg)
1085 1102
 
1086 1103
 	set_to_acl = cfg.acl_public and "Public" or "Private"
1087 1104
 
1105
+	if not cfg.recursive:
1106
+		old_args = args
1107
+		args = []
1108
+		for arg in old_args:
1109
+			uri = S3Uri(arg)
1110
+			if not uri.has_object():
1111
+				info("Setting bucket-level ACL for %s to %s" % (uri.uri(), set_to_acl))
1112
+				if not cfg.dry_run:
1113
+					_update_acl(uri)
1114
+			else:
1115
+				args.append(arg)
1116
+
1088 1117
 	remote_list = fetch_remote_list(args)
1089 1118
 	remote_list, exclude_list = _filelist_filter_exclude_include(remote_list)
1090 1119
 
... ...
@@ -1106,21 +1135,7 @@ def cmd_setacl(args):
1106 1106
 		seq += 1
1107 1107
 		seq_label = "[%d of %d]" % (seq, remote_count)
1108 1108
 		uri = S3Uri(remote_list[key]['object_uri_str'])
1109
-		acl = s3.get_acl(uri)
1110
-		debug(u"acl: %s - %r" % (uri, acl.grantees))
1111
-		if cfg.acl_public:
1112
-			if acl.isAnonRead():
1113
-				info(u"%s: already Public, skipping %s" % (uri, seq_label))
1114
-				continue
1115
-			acl.grantAnonRead()
1116
-		else:
1117
-			if not acl.isAnonRead():
1118
-				info(u"%s: already Private, skipping %s" % (uri, seq_label))
1119
-				continue
1120
-			acl.revokeAnonRead()
1121
-		retsponse = s3.set_acl(uri, acl)
1122
-		if retsponse['status'] == 200:
1123
-			output(u"%s: ACL set to %s  %s" % (uri, set_to_acl, seq_label))
1109
+		_update_acl(uri, seq_label)
1124 1110
 
1125 1111
 def cmd_accesslog(args):
1126 1112
 	s3 = S3(cfg)