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... | ... |
@@ -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): |