Merge remote-tracking branch 'cwebber/254_delete_queue_directories'
* cwebber/254_delete_queue_directories: Removing docstring bit about delete_file possibly deleting directories in the future Convert media processing backends to delete the queue directory (#254) Implement delete_dir in the FileStorage Conflicts: mediagoblin/media_types/image/processing.py mediagoblin/media_types/video/processing.py Conflicts, because those media_types already use the newer proc_state.delete_queue_file() method (which needs updating.
This commit is contained in:
@@ -101,10 +101,20 @@ class StorageInterface(object):
|
||||
|
||||
def delete_file(self, filepath):
|
||||
"""
|
||||
Delete or dereference the file at filepath.
|
||||
Delete or dereference the file (not directory) at filepath.
|
||||
"""
|
||||
# Subclasses should override this method.
|
||||
self.__raise_not_implemented()
|
||||
|
||||
This might need to delete directories, buckets, whatever, for
|
||||
cleanliness. (Be sure to avoid race conditions on that though)
|
||||
def delete_dir(self, dirpath, recursive=False):
|
||||
"""Delete the directory at dirpath
|
||||
|
||||
:param recursive: Usually, a directory must not contain any
|
||||
files for the delete to succeed. If True, containing files
|
||||
and subdirectories within dirpath will be recursively
|
||||
deleted.
|
||||
|
||||
:returns: True in case of success, False otherwise.
|
||||
"""
|
||||
# Subclasses should override this method.
|
||||
self.__raise_not_implemented()
|
||||
|
||||
@@ -62,10 +62,32 @@ class BasicFileStorage(StorageInterface):
|
||||
return open(self._resolve_filepath(filepath), mode)
|
||||
|
||||
def delete_file(self, filepath):
|
||||
# TODO: Also delete unused directories if empty (safely, with
|
||||
# checks to avoid race conditions).
|
||||
"""Delete file at filepath
|
||||
|
||||
Raises OSError in case filepath is a directory."""
|
||||
#TODO: log error
|
||||
os.remove(self._resolve_filepath(filepath))
|
||||
|
||||
def delete_dir(self, dirpath, recursive=False):
|
||||
"""returns True on succes, False on failure"""
|
||||
|
||||
dirpath = self._resolve_filepath(dirpath)
|
||||
|
||||
# Shortcut the default and simple case of nonempty=F, recursive=F
|
||||
if recursive:
|
||||
try:
|
||||
shutil.rmtree(dirpath)
|
||||
except OSError as e:
|
||||
#TODO: log something here
|
||||
return False
|
||||
else: # recursively delete everything
|
||||
try:
|
||||
os.rmdir(dirpath)
|
||||
except OSError as e:
|
||||
#TODO: log something here
|
||||
return False
|
||||
return True
|
||||
|
||||
def file_url(self, filepath):
|
||||
if not self.base_url:
|
||||
raise NoWebServing(
|
||||
|
||||
Reference in New Issue
Block a user