def __init__(self, swiftfilesystem, fullpath): self.swiftfilesystem = swiftfilesystem self.fullpath = fullpath # A lot of clients require . and .. to be within the directory listing self.files = OrderedDict([ ('.', {}), ('..', {}), ])
def get_container_listing(self, container, path, marker=None, all_files=None): if all_files is None: all_files = OrderedDict() prefix = None if path: prefix = "%s/" % path d = self.swiftconn.get_container(container, prefix=prefix, delimiter='/', marker=marker) def cb(results): _, files = results next_marker = None for f in files: if 'subdir' in f: f['name'] = f['subdir'] f['content-type'] = 'application/directory' f['formatted_name'] = os.path.basename( f['name'].encode("utf-8").rstrip('/')) all_files[f['formatted_name']] = f next_marker = f['name'] if len(files) > 0: return self.get_container_listing(container, path, marker=next_marker, all_files=all_files) return all_files d.addCallback(cb) return d
def __init__(self, swiftfilesystem, fullpath): self.swiftfilesystem = swiftfilesystem self.fullpath = fullpath # A lot of clients require . and .. to be within the directory listing self.files = OrderedDict( [ ('.', {}), ('..', {}), ])
class SwiftDirectory(object): "Swift Directory is an iterator that returns a listing of the directory." def __init__(self, swiftfilesystem, fullpath): self.swiftfilesystem = swiftfilesystem self.fullpath = fullpath # A lot of files require . and .. to be within the directory listing self.files = OrderedDict([(".", {}), ("..", {})]) self.done = False def get_full_listing(self): "Populate the directory listing." def cb(results): for k, v in results.iteritems(): self.files[k] = v d = self.swiftfilesystem.get_full_listing(self.fullpath) d.addCallback(cb) return d def __iter__(self): return self def next(self): try: name, f = self.files.popitem(last=False) lstat = swift_stat(**f) longname = ls.lsLine(name, lstat) return ( name, longname, { "size": lstat.st_size, "uid": lstat.st_uid, "gid": lstat.st_gid, "permissions": lstat.st_mode, "atime": int(lstat.st_atime), "mtime": int(lstat.st_mtime), }, ) except KeyError: raise StopIteration def close(self): self.files = [] self.offset = 0
class SwiftDirectory(object): "Swift Directory is an iterator that returns a listing of the directory." def __init__(self, swiftfilesystem, fullpath): self.swiftfilesystem = swiftfilesystem self.fullpath = fullpath # A lot of clients require . and .. to be within the directory listing self.files = OrderedDict([ ('.', {}), ('..', {}), ]) def get_full_listing(self): "Populate the directory listing." def cb(results): for k, v in results.iteritems(): self.files[k] = v d = self.swiftfilesystem.get_full_listing(self.fullpath) d.addCallback(cb) return d def __iter__(self): return self def next(self): try: name, f = self.files.popitem(last=False) lstat = swift_stat(**f) longname = ls.lsLine(name, lstat) return (name, longname, { "size": lstat.st_size, "uid": lstat.st_uid, "gid": lstat.st_gid, "permissions": lstat.st_mode, "atime": int(lstat.st_atime), "mtime": int(lstat.st_mtime) }) except KeyError: raise StopIteration def close(self): self.files = [] self.offset = 0
def get_account_listing(self, marker=None, all_files=None): if all_files is None: all_files = OrderedDict() d = self.swiftconn.get_account(marker=marker) def cb(results): _, files = results next_marker = None for f in files: f['content-type'] = 'application/directory' f['formatted_name'] = f['name'].encode("utf-8") all_files[f['formatted_name']] = f next_marker = f['name'] if len(files) > 0: return self.get_account_listing(marker=next_marker, all_files=all_files) return all_files d.addCallback(cb) return d
def __init__(self, swiftfilesystem, fullpath): self.swiftfilesystem = swiftfilesystem self.fullpath = fullpath # A lot of files require . and .. to be within the directory listing self.files = OrderedDict([(".", {}), ("..", {})]) self.done = False