def set_file(self, obj_file, filename): temp_files = set() # noinspection PyBroadException try: self.remove_file() self.archive_key = storage( settings.STORAGE_ARCHIVE).store_descriptor( self.uuid, filename, obj_file) uncompressed_path = None for mw in archive_filters(): obj_file.seek(0) u_path = mw(self, obj_file, filename, temp_files, uncompressed_path) if u_path is not None: uncompressed_path = u_path if uncompressed_path is not None: # there are extracted data to store self.uncompressed_key = storage( settings.STORAGE_UNCOMPRESSED).store( self.uuid, uncompressed_path) except Exception as e: logging.error(gettext('Unable to add the archive file'), exc_info=True) raise e obj_file.seek(0) for f in temp_files: remove(f)
def remove_dir(dirname): """ recursively delete empty directories :param dirname: directory to remove :return: None """ if not os.path.exists(dirname): return if len(os.listdir(dirname)) > 0 or dirname == self.root: return remove(dirname) remove_dir(os.path.dirname(dirname))
def set_file(self, obj_file, filename): temp_files = set() # noinspection PyBroadException try: self.remove_file() self.archive_key = storage(settings.STORAGE_ARCHIVE).store_descriptor(self.uuid, filename, obj_file) uncompressed_path = None for mw in archive_filters(): obj_file.seek(0) u_path = mw(self, obj_file, filename, temp_files, uncompressed_path) if u_path is not None: uncompressed_path = u_path if uncompressed_path is not None: # there are extracted data to store self.uncompressed_key = storage(settings.STORAGE_UNCOMPRESSED).store(self.uuid, uncompressed_path) except Exception as e: logging.error(ugettext('Unable to add the archive file'), exc_info=True) raise e obj_file.seek(0) for f in temp_files: remove(f)
def delete(self, key): """ Delete the element from its internal storage :param key: UUID of the Element to delete :raise: """ abs_path = os.path.join(self.root, key) def remove_dir(dirname): """ recursively delete empty directories :param dirname: directory to remove :return: None """ if not os.path.exists(dirname): return if len(os.listdir(dirname)) > 0 or dirname == self.root: return remove(dirname) remove_dir(os.path.dirname(dirname)) result = remove(abs_path) remove_dir(os.path.dirname(abs_path)) return result