Created
October 29, 2013 20:56
-
-
Save jonasfj/7222444 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def list_partitions(bucket, prefix='', level=0, schema=None, include_keys=False): | |
#print "Listing...", prefix, level | |
if schema is not None: | |
allowed_values = schema.sanitize_allowed_values() | |
delimiter = '/' | |
if level > 3: | |
delimiter = '.' | |
for k in bucket.list(prefix=prefix, delimiter=delimiter): | |
partitions = k.name.split("/") | |
if level > 3: | |
# split the last couple of partition components by "." instead of "/" | |
partitions.extend(partitions.pop().split(".", 2)) | |
if schema is None or schema.is_allowed(partitions[level], allowed_values[level]): | |
if level >= 5: | |
if include_keys: | |
for f in bucket.list(prefix=k.name): | |
yield f | |
else: | |
yield k.name | |
else: | |
for prefix in list_partitions(bucket, k.name, level + 1, schema, include_keys): | |
yield prefix |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment