Browse code

* S3/S3.py: Support for buckets with over 1000 objects.

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

Michal Ludvig authored on 2007/09/13 15:10:59
Showing 3 changed files
... ...
@@ -1,3 +1,7 @@
1
+2007-09-13  Michal Ludvig  <michal@logix.cz>
2
+
3
+	* S3/S3.py: Support for buckets with over 1000 objects.
4
+
1 5
 2007-09-03  Michal Ludvig  <michal@logix.cz>
2 6
 
3 7
 	* s3cmd: Small tweaks to --configure workflow.
... ...
@@ -2,6 +2,7 @@ s3cmd 0.9.5   -   ???
2 2
 ===========
3 3
 * Much better handling of multiple args to put, get and del
4 4
 * Tries to use ElementTree from any available module
5
+* Support for buckets with over 1000 objects.
5 6
 
6 7
 s3cmd 0.9.4   -   2007-08-13
7 8
 ===========
... ...
@@ -105,14 +105,23 @@ class S3(object):
105 105
 		return response
106 106
 	
107 107
 	def bucket_list(self, bucket, prefix = None):
108
-		## TODO: use prefix if supplied
108
+		def _list_truncated(data):
109
+			return getTextFromXml(data, ".//IsTruncated").lower() != "false"
110
+
111
+		def _get_contents(data):
112
+			return getListFromXml(data, "Contents")
113
+
109 114
 		request = self.create_request("BUCKET_LIST", bucket = bucket, prefix = prefix)
110 115
 		response = self.send_request(request)
111 116
 		#debug(response)
112
-		response["list"] = getListFromXml(response["data"], "Contents")
113
-		is_truncated = getTextFromXml(response['data'], ".//IsTruncated")
114
-		if is_truncated and is_truncated.lower() != "false":
115
-			raise Exception("Listing truncated. Please notify s3cmd developers.")
117
+		list = _get_contents(response["data"])
118
+		while _list_truncated(response["data"]):
119
+			marker = list[-1]["Key"]
120
+			info("Listing continues after '%s'" % marker)
121
+			request = self.create_request("BUCKET_LIST", bucket = bucket, prefix = prefix, marker = marker)
122
+			response = self.send_request(request)
123
+			list += _get_contents(response["data"])
124
+		response['list'] = list
116 125
 		return response
117 126
 
118 127
 	def bucket_create(self, bucket):