From 0b1951a4a451ec21f620dabe91530d89a02c0898 Mon Sep 17 00:00:00 2001 From: Jake Moshenko Date: Thu, 14 Jan 2016 15:29:22 -0500 Subject: [PATCH] Remove list directory from storage driver --- storage/basestorage.py | 3 --- storage/cloud.py | 21 ------------------- storage/distributedstorage.py | 1 - storage/local.py | 12 ----------- storage/swift.py | 39 ----------------------------------- 5 files changed, 76 deletions(-) diff --git a/storage/basestorage.py b/storage/basestorage.py index fd9ca30e1..dd638c0ad 100644 --- a/storage/basestorage.py +++ b/storage/basestorage.py @@ -74,9 +74,6 @@ class BaseStorage(StoragePaths): def stream_write(self, path, fp, content_type=None, content_encoding=None): raise NotImplementedError - def list_directory(self, path=None): - raise NotImplementedError - def exists(self, path): raise NotImplementedError diff --git a/storage/cloud.py b/storage/cloud.py index 4c0ee9d60..2f0be6838 100644 --- a/storage/cloud.py +++ b/storage/cloud.py @@ -210,27 +210,6 @@ class _CloudStorage(BaseStorageV2): mp.complete_upload() return total_bytes_written, error - def list_directory(self, path=None): - self._initialize_cloud_conn() - path = self._init_path(path) - if not path.endswith('/'): - path += '/' - ln = 0 - if self._root_path != '/': - ln = len(self._root_path) - exists = False - for key in self._cloud_bucket.list(prefix=path, delimiter='/'): - exists = True - name = key.name - if name.endswith('/'): - yield name[ln:-1] - else: - yield name[ln:] - if exists is False: - # In order to be compliant with the LocalStorage API. Even though - # S3 does not have a concept of folders. - raise OSError('No such directory: \'{0}\''.format(path)) - def exists(self, path): self._initialize_cloud_conn() path = self._init_path(path) diff --git a/storage/distributedstorage.py b/storage/distributedstorage.py index 3e94a3dd4..b4d8e08e7 100644 --- a/storage/distributedstorage.py +++ b/storage/distributedstorage.py @@ -44,7 +44,6 @@ class DistributedStorage(StoragePaths): stream_read = _location_aware(BaseStorage.stream_read) stream_read_file = _location_aware(BaseStorage.stream_read_file) stream_write = _location_aware(BaseStorage.stream_write) - list_directory = _location_aware(BaseStorage.list_directory) exists = _location_aware(BaseStorage.exists) remove = _location_aware(BaseStorage.remove) get_checksum = _location_aware(BaseStorage.get_checksum) diff --git a/storage/local.py b/storage/local.py index d574293bc..7f92d6652 100644 --- a/storage/local.py +++ b/storage/local.py @@ -56,18 +56,6 @@ class LocalStorage(BaseStorageV2): with open(path, mode='wb') as out_fp: self.stream_write_to_fp(fp, out_fp) - def list_directory(self, path=None): - path = self._init_path(path) - prefix = path[len(self._root_path) + 1:] + '/' - exists = False - for d in os.listdir(path): - exists = True - yield prefix + d - if exists is False: - # Raises OSError even when the directory is empty - # (to be consistent with S3) - raise OSError('No such directory: \'{0}\''.format(path)) - def exists(self, path): path = self._init_path(path) return os.path.exists(path) diff --git a/storage/swift.py b/storage/swift.py index 472a8c92f..5a0a5b92a 100644 --- a/storage/swift.py +++ b/storage/swift.py @@ -61,15 +61,6 @@ class SwiftStorage(BaseStorage): auth_version=self._auth_version, os_options=self._os_options) - def _get_relative_path(self, path): - if path.startswith(self._storage_path): - path = path[len(self._storage_path)] - - if path.endswith('/'): - path = path[:-1] - - return path - def _normalize_path(self, object_path=None): path = self._storage_path if not path.endswith('/'): @@ -87,20 +78,6 @@ class SwiftStorage(BaseStorage): return path - def _get_container(self, path): - path = self._normalize_path(path) - - if path and not path.endswith('/'): - path += '/' - - try: - _, container = self._get_connection().get_container( - container=self._swift_container, - prefix=path, delimiter='/') - return container - except: - logger.exception('Could not get container: %s', path) - raise IOError('Unknown path: %s' % path) def _get_object(self, path, chunk_size=None): path = self._normalize_path(path) @@ -218,22 +195,6 @@ class SwiftStorage(BaseStorage): self._put_object(path, fp, self.buffer_size, content_type=content_type, content_encoding=content_encoding) - def list_directory(self, path=None): - container = self._get_container(path) - if not container: - raise OSError('Unknown path: %s' % path) - - for entry in container: - param = None - if 'name' in entry: - param = 'name' - elif 'subdir' in entry: - param = 'subdir' - else: - continue - - yield self._get_relative_path(entry[param]) - def exists(self, path): return bool(self._head_object(path))