def __init__(self, base_dir): """ Initialize a new storage backend instance that will work within 'base_dir'. :param base_dir: The base directory within which should be worked. """ if not os.path.exists(base_dir): raise DirectoryNotFoundError("Base directory does not exist.") self.base_dir = base_dir
def get_full_dir_path(self, dir_name, **kwargs): """ :inherit. """ if not self.dir_exists(dir_name): raise DirectoryNotFoundError("Directory does not exist.") try: return self._fs.get_full_path(dir_name) except Exception as ex: raise StorageBackendError(ex)
def set_dir_uid(self, dir_name, uid, **kwargs): """ :inherit. """ if not self.dir_exists(dir_name): raise DirectoryNotFoundError("Directory does not exist.") try: self._fs.set_uid(uid, dir_name) except Exception as ex: raise StorageBackendError(ex)
def rm_dir(self, dir_name, **kwargs): """ :inherit. :param recursive: If true, recursively remove the dir. If false and the directory is not empty, an error is raised. """ if not self.dir_exists(dir_name): raise DirectoryNotFoundError("Directory does not exist.") recursive = kwargs.get('recursive') try: if recursive is True: self._fs.rrm_dir(dir_name) else: self._fs.rm_dir(dir_name) except Exception as ex: raise StorageBackendError(ex)