def has_existing_archive(self, category): path = Path(self.location, category.name) os.makedirs(str(path), exist_ok=True) for subpath in path.glob('*'): if subpath.is_file() and fs.is_archive(str(subpath)): return True return False
def _add_to_sip(self, name, content, category: FileCategoryDirectories): sip_storage = self.get_sip_storage() filename = self.originals_dir.joinpath(name) if fs.is_archive(name): archive_extractor = ArchiveExtractor(sip_storage) return archive_extractor.process(category=category, filename=str(filename)) else: return sip_storage.log_save(name=name, content=content)
def validate_file(self, name, content): msgs = super().validate_file(name, content) category = get_category(name) if self.has_existing_archive(category): msgs.append(self.error( 'File cannot be added to directory with archive in it. Please clear category and try again.')) if os.listdir(os.path.join(self.location, category.name)) and fs.is_archive(name): msgs.append([self.error('Archive cannot be added to a directory that already has files in it. ' 'Please clear category and try again')]) return msgs
def validate_file(self, name, content): msgs = super().validate_file(name, content) category = get_category(name) if self.has_existing_archive(category): msgs.append(self.error( 'This file cannot be added because files have already been archived here.' ' Please remove all files and try again.')) if os.listdir(os.path.join(self.location, category.name)) and fs.is_archive(name): msgs.append(self.error( 'This archive cannot be added because files have already been archived here. ' 'Please remove all files and try again.')) return msgs
def is_archive_directory(self, category): for p in self.list(category, absolute=True): if p.is_file() and fs.is_archive(str(p)): return True return False
def get_existing_archive_name(self, category: FileCategoryDirectories): for p in self.list(category): if p.is_file() and fs.is_archive(p): return str(p) return None