From db8097ed3cb54799674039682c2b5ab8f3b589c6 Mon Sep 17 00:00:00 2001 From: Brian Pepple Date: Fri, 8 Oct 2021 22:54:41 -0400 Subject: [PATCH] Extract duplicate code from methods into a new one --- darkseid/comicarchive.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/darkseid/comicarchive.py b/darkseid/comicarchive.py index e58ac58..cf9295e 100644 --- a/darkseid/comicarchive.py +++ b/darkseid/comicarchive.py @@ -268,24 +268,25 @@ def write_metadata(self, metadata: GenericMetadata) -> bool: self.apply_archive_info_to_metadata(metadata, calc_page_sizes=True) md_string = ComicInfoXml().string_from_metadata(metadata) write_success = self.archiver.write_archive_file(self.ci_xml_filename, md_string) - if write_success: - self.has_md = True - self.metadata = metadata - self.reset_cache() - return write_success + return self._successful_write(write_success, True, metadata) def remove_metadata(self) -> bool: """Remove the metadata from the archive if present""" if self.has_metadata(): write_success = self.archiver.remove_archive_file(self.ci_xml_filename) - if write_success: - self.has_md = False - self.metadata = None - self.reset_cache() - return write_success + return self._successful_write(write_success, False, None) return True + def _successful_write( + self, write_success: bool, has_md: bool, metadata: Optional[GenericMetadata] + ) -> bool: + if write_success: + self.has_md = has_md + self.metadata = metadata + self.reset_cache() + return write_success + def has_metadata(self) -> bool: """Checks to see if the archive has metadata"""