Skip to content

Instantly share code, notes, and snippets.

@sathlan
Created September 18, 2014 05:18
Show Gist options
  • Save sathlan/ac9951fdeb3fb13f4c2d to your computer and use it in GitHub Desktop.
Save sathlan/ac9951fdeb3fb13f4c2d to your computer and use it in GitHub Desktop.
mocked docker registry swift get_container function.
''' Get a listing of objects for the container. '''
def get_container(self, container, marker=None, limit=None, prefix=None,
delimiter=None, end_marker=None, path=None,
full_listing=False):
lst = []
search = path
if search is None:
search = prefix
for key, value in self._swift_containers[container].iteritems():
# works only for two level deep path. Enough to test.
if delimiter is None and prefix is not None:
# This output all the files matching the prefix,
# regardless of how deep they are.
path_re = re.compile("(%s/?)(.+)?$" % search)
else:
# This match the case where delimiter is "/" and
# prefix is set or the case where path is set. Good
# enough.
path_re = re.compile("(%s/?)([^/]+)(/.*)?$" % search)
match = path_re.match(key)
if match is not None:
if match.group(3) is not None:
# we have a subdir
hash_key = 'subdir'
suffix = '/'
else:
# we have a file
hash_key = 'name'
suffix = ''
found_file = match.group(1) + match.group(2) + suffix
lst.append({hash_key: found_file})
print("%s" % lst)
return None, lst
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment