OLD | NEW |
(Empty) | |
| 1 # Copyright 2012 Google Inc. |
| 2 # Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/ |
| 3 # |
| 4 # Permission is hereby granted, free of charge, to any person obtaining a |
| 5 # copy of this software and associated documentation files (the |
| 6 # "Software"), to deal in the Software without restriction, including |
| 7 # without limitation the rights to use, copy, modify, merge, publish, dis- |
| 8 # tribute, sublicense, and/or sell copies of the Software, and to permit |
| 9 # persons to whom the Software is furnished to do so, subject to the fol- |
| 10 # lowing conditions: |
| 11 # |
| 12 # The above copyright notice and this permission notice shall be included |
| 13 # in all copies or substantial portions of the Software. |
| 14 # |
| 15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- |
| 17 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT |
| 18 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 19 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 # IN THE SOFTWARE. |
| 22 |
| 23 def versioned_bucket_lister(bucket, prefix='', delimiter='', |
| 24 marker='', generation_marker='', headers=None): |
| 25 """ |
| 26 A generator function for listing versioned objects. |
| 27 """ |
| 28 more_results = True |
| 29 k = None |
| 30 while more_results: |
| 31 rs = bucket.get_all_versions(prefix=prefix, marker=marker, |
| 32 generation_marker=generation_marker, |
| 33 delimiter=delimiter, headers=headers, |
| 34 max_keys=999) |
| 35 for k in rs: |
| 36 yield k |
| 37 marker = rs.next_marker |
| 38 generation_marker = rs.next_generation_marker |
| 39 more_results= rs.is_truncated |
| 40 |
| 41 class VersionedBucketListResultSet: |
| 42 """ |
| 43 A resultset for listing versions within a bucket. Uses the bucket_lister |
| 44 generator function and implements the iterator interface. This |
| 45 transparently handles the results paging from GCS so even if you have |
| 46 many thousands of keys within the bucket you can iterate over all |
| 47 keys in a reasonably efficient manner. |
| 48 """ |
| 49 |
| 50 def __init__(self, bucket=None, prefix='', delimiter='', marker='', |
| 51 generation_marker='', headers=None): |
| 52 self.bucket = bucket |
| 53 self.prefix = prefix |
| 54 self.delimiter = delimiter |
| 55 self.marker = marker |
| 56 self.generation_marker = generation_marker |
| 57 self.headers = headers |
| 58 |
| 59 def __iter__(self): |
| 60 return versioned_bucket_lister(self.bucket, prefix=self.prefix, |
| 61 delimiter=self.delimiter, |
| 62 marker=self.marker, |
| 63 generation_marker=self.generation_marker, |
| 64 headers=self.headers) |
OLD | NEW |