From 9902a7872d046e24204a9c8ed91f39c391b5bc80 Mon Sep 17 00:00:00 2001 From: hyugogirubato <65763543+hyugogirubato@users.noreply.github.com> Date: Sun, 7 Jul 2024 18:49:43 +0200 Subject: [PATCH] standardize quotes --- cbz/comic.py | 14 +++---- cbz/constants.py | 102 +++++++++++++++++++++++------------------------ cbz/models.py | 68 +++++++++++++++---------------- cbz/ui.py | 24 +++++------ cbz/utils.py | 3 +- 5 files changed, 105 insertions(+), 106 deletions(-) diff --git a/cbz/comic.py b/cbz/comic.py index 092307a..1dc765b 100644 --- a/cbz/comic.py +++ b/cbz/comic.py @@ -23,7 +23,7 @@ class ComicInfo(ComicModel): def dumps(self) -> dict: return utils.dumps(self._get() | { - "Pages": [{'Image': i, **page.dumps()} for i, page in enumerate(self.__pages)], + 'Pages': [{'Image': i, **page.dumps()} for i, page in enumerate(self.__pages)], 'PageCount': len(self.__pages) }) @@ -65,7 +65,7 @@ class ComicInfo(ComicModel): with Path(path).open(mode='rb') as f: with zipfile.ZipFile(f, 'r', zipfile.ZIP_STORED) as zip_file: xml_file = zip_file.open(xml_name) - info = xmltodict.parse(xml_file.read()).get("ComicInfo", {}) + info = xmltodict.parse(xml_file.read()).get('ComicInfo', {}) xml_file.close() return info @@ -87,22 +87,22 @@ class ComicInfo(ComicModel): Save changes to opened from file or already saved to file comic :return: """ - assert self._filepath, "Use to_cbz or from_cbz before save changes" + assert self._filepath, 'Use to_cbz or from_cbz before save changes' self.to_cbz(self._filepath) @staticmethod def __unpack(file_path: Path) -> dict: with zipfile.ZipFile(file_path, 'r', zipfile.ZIP_STORED) as zip_file: _files = zip_file.namelist() - assert xml_name in _files, f"{xml_name} not found in: {zip_file.filename}" + assert xml_name in _files, f'{xml_name} not found in: {zip_file.filename}' xml_file = zip_file.open(xml_name) - info = xmltodict.parse(xml_file.read()).get("ComicInfo", {}) + info = xmltodict.parse(xml_file.read()).get('ComicInfo', {}) xml_file.close() _files.remove(xml_name) - info["pages"] = list() + info['pages'] = list() for filename in _files: page_file = zip_file.open(filename) - info["pages"].append(PageInfo.loads(page_file.read())) + info['pages'].append(PageInfo.loads(page_file.read())) page_file.close() return info diff --git a/cbz/constants.py b/cbz/constants.py index 952f008..c905d36 100644 --- a/cbz/constants.py +++ b/cbz/constants.py @@ -1,7 +1,7 @@ from enum import Enum from langcodes import Language -xml_name = "ComicInfo.xml" +xml_name = 'ComicInfo.xml' class YesNo(Enum): @@ -119,58 +119,58 @@ class ValidLanguage(str): FIELDS = ( # model: (key, xml key): (variable name, (expected type, second expected type,...)) # in case of multiple expected formats, value cast to first type in tuple - (("title", "Title"), ("title", (str,))), - (("series", "Series"), ("series", (str,))), - (("number", "Number"), ("number", (str, int, float))), - (("count", "Count"), ("count", (int,))), - (("volume", "Volume"), ("volume", (int,))), - (("alternate_series", "AlternateSeries"), ("alternate_series", (str,))), - (("alternate_number", "AlternateNumber"), ("alternate_number", (str, int, float))), - (("alternate_count", "AlternateCount"), ("alternate_count", (int,))), - (("summary", "Summary"), ("summary", (str,))), - (("notes", "Notes"), ("notes", (str,))), - (("year", "Year"), ("year", (int,))), - (("month", "Month"), ("month", (int,))), - (("day", "Day"), ("day", (int,))), - (("writer", "Writer"), ("writer", (str,))), - (("penciller", "Penciller"), ("penciller", (str,))), - (("inker", "Inker"), ("inker", (str,))), - (("colorist", "Colorist"), ("colorist", (str,))), - (("letterer", "Letterer"), ("letterer", (str,))), - (("cover_artist", "CoverArtist"), ("cover_artist", (str,))), - (("editor", "Editor"), ("editor", (str,))), - (("translator", "Translator"), ("translator", (str,))), - (("publisher", "Publisher"), ("publisher", (str,))), - (("imprint", "Imprint"), ("imprint", (str,))), - (("genre", "Genre"), ("genre", (str,))), - (("tags", "Tags"), ("tags", (str,))), - (("web", "Web"), ("web", (str,))), - (("format", "Format"), ("format", (Format, str))), - (("ean", "EAN"), ("ean", (str,))), - (("black_white", "BlackAndWhite"), ("black_white", (YesNo, str))), - (("manga", "Manga"), ("manga", (Manga, str))), - (("characters", "Characters"), ("characters", (str,))), - (("teams", "Teams"), ("teams", (str,))), - (("locations", "Locations"), ("locations", (str,))), - (("scan_information", "ScanInformation"), ("scan_information", (str,))), - (("story_arc", "StoryArc"), ("story_arc", (str,))), - (("story_arc_number", "StoryArcNumber"), ("story_arc_number", (str,))), - (("series_group", "SeriesGroup"), ("series_group", (str,))), - (("age_rating", "AgeRating"), ("age_rating", (AgeRating, str))), - (("main_character_or_team", "MainCharacterOrTeam"), ("main_character_or_team", (str,))), - (("review", "Review"), ("review", (str,))), - (("language_iso", "LanguageISO"), ("language_iso", (ValidLanguage, str))), - (("community_rating", "CommunityRating"), ("community_rating", (ValidRating, float, int, str))), + (('title', 'Title'), ('title', (str,))), + (('series', 'Series'), ('series', (str,))), + (('number', 'Number'), ('number', (str, int, float))), + (('count', 'Count'), ('count', (int,))), + (('volume', 'Volume'), ('volume', (int,))), + (('alternate_series', 'AlternateSeries'), ('alternate_series', (str,))), + (('alternate_number', 'AlternateNumber'), ('alternate_number', (str, int, float))), + (('alternate_count', 'AlternateCount'), ('alternate_count', (int,))), + (('summary', 'Summary'), ('summary', (str,))), + (('notes', 'Notes'), ('notes', (str,))), + (('year', 'Year'), ('year', (int,))), + (('month', 'Month'), ('month', (int,))), + (('day', 'Day'), ('day', (int,))), + (('writer', 'Writer'), ('writer', (str,))), + (('penciller', 'Penciller'), ('penciller', (str,))), + (('inker', 'Inker'), ('inker', (str,))), + (('colorist', 'Colorist'), ('colorist', (str,))), + (('letterer', 'Letterer'), ('letterer', (str,))), + (('cover_artist', 'CoverArtist'), ('cover_artist', (str,))), + (('editor', 'Editor'), ('editor', (str,))), + (('translator', 'Translator'), ('translator', (str,))), + (('publisher', 'Publisher'), ('publisher', (str,))), + (('imprint', 'Imprint'), ('imprint', (str,))), + (('genre', 'Genre'), ('genre', (str,))), + (('tags', 'Tags'), ('tags', (str,))), + (('web', 'Web'), ('web', (str,))), + (('format', 'Format'), ('format', (Format, str))), + (('ean', 'EAN'), ('ean', (str,))), + (('black_white', 'BlackAndWhite'), ('black_white', (YesNo, str))), + (('manga', 'Manga'), ('manga', (Manga, str))), + (('characters', 'Characters'), ('characters', (str,))), + (('teams', 'Teams'), ('teams', (str,))), + (('locations', 'Locations'), ('locations', (str,))), + (('scan_information', 'ScanInformation'), ('scan_information', (str,))), + (('story_arc', 'StoryArc'), ('story_arc', (str,))), + (('story_arc_number', 'StoryArcNumber'), ('story_arc_number', (str,))), + (('series_group', 'SeriesGroup'), ('series_group', (str,))), + (('age_rating', 'AgeRating'), ('age_rating', (AgeRating, str))), + (('main_character_or_team', 'MainCharacterOrTeam'), ('main_character_or_team', (str,))), + (('review', 'Review'), ('review', (str,))), + (('language_iso', 'LanguageISO'), ('language_iso', (ValidLanguage, str))), + (('community_rating', 'CommunityRating'), ('community_rating', (ValidRating, float, int, str))), ) PAGE_FIELDS = ( # model: (key, xml key): (variable name, (expected type, second expected type,...)) # in case of multiple expected formats, value cast to first type in tuple - (("type", "Type"), ("type", (PageType, str))), - (("double", "DoublePage"), ("double", (bool,))), - (("key", "Key"), ("key", (str,))), - (("bookmark", "Bookmark"), ("bookmark", (str,))), - (("image_size", "ImageSize"), ("_image_size", (int,))), - (("image_width", "ImageWidth"), ("_image_width", (int,))), - (("image_height", "ImageHeight"), ("_image_height", (int,))), -) \ No newline at end of file + (('type', 'Type'), ('type', (PageType, str))), + (('double', 'DoublePage'), ('double', (bool,))), + (('key', 'Key'), ('key', (str,))), + (('bookmark', 'Bookmark'), ('bookmark', (str,))), + (('image_size', 'ImageSize'), ('_image_size', (int,))), + (('image_width', 'ImageWidth'), ('_image_width', (int,))), + (('image_height', 'ImageHeight'), ('_image_height', (int,))), +) diff --git a/cbz/models.py b/cbz/models.py index 2430a0c..3cccd90 100644 --- a/cbz/models.py +++ b/cbz/models.py @@ -3,49 +3,49 @@ from cbz.utils import _get, _set class ComicModel: - title: str = "" - series: str = "" - number: str = "" + title: str = '' + series: str = '' + number: str = '' count: int = -1 volume: int = -1 - alternate_series: str = "" - alternate_number: str = "" + alternate_series: str = '' + alternate_number: str = '' alternate_count: int = -1 - summary: str = "" - notes: str = "" + summary: str = '' + notes: str = '' year: int = -1 month: int = -1 day: int = -1 - writer: str = "" - penciller: str = "" - inker: str = "" - colorist: str = "" - letterer: str = "" - cover_artist: str = "" - editor: str = "" - translator: str = "" - publisher: str = "" - imprint: str = "" - genre: str = "" - tags: str = "" - web: str = "" - language_iso: str = "" + writer: str = '' + penciller: str = '' + inker: str = '' + colorist: str = '' + letterer: str = '' + cover_artist: str = '' + editor: str = '' + translator: str = '' + publisher: str = '' + imprint: str = '' + genre: str = '' + tags: str = '' + web: str = '' + language_iso: str = '' format: Format = Format.UNKNOWN - ean: str = "" + ean: str = '' black_white: YesNo = YesNo.UNKNOWN manga: Manga = Manga.UNKNOWN - characters: str = "" - teams: str = "" - locations: str = "" - scan_information: str = "" - story_arc: str = "" - story_arc_number: str = "" - series_group: str = "" + characters: str = '' + teams: str = '' + locations: str = '' + scan_information: str = '' + story_arc: str = '' + story_arc_number: str = '' + series_group: str = '' age_rating: AgeRating = AgeRating.UNKNOWN community_rating: int = -1 - main_character_or_team: str = "" - review: str = "" - _filepath: str = "" + main_character_or_team: str = '' + review: str = '' + _filepath: str = '' def __init__(self, kwargs: dict): _set(self, FIELDS, kwargs) @@ -60,8 +60,8 @@ class PageModel: type: PageType = PageType.STORY double: bool = False _image_size: int = 0 - key: str = "" - bookmark: str = "" + key: str = '' + bookmark: str = '' _image_width: int = 0 _image_height: int = 0 diff --git a/cbz/ui.py b/cbz/ui.py index 1a48463..d75de1b 100644 --- a/cbz/ui.py +++ b/cbz/ui.py @@ -6,7 +6,7 @@ from PIL import ImageTk, Image class ScrolledCanvas(Frame): image_cursor: int = -2 - info_text: str = "" + info_text: str = '' pages = list() next_btn = None prev_btn = None @@ -15,7 +15,7 @@ class ScrolledCanvas(Frame): def __init__(self, parent=None): Frame.__init__(self, parent) - self.master.title("Spectrogram Viewer") + self.master.title('Spectrogram Viewer') self.pack(expand=YES, fill=BOTH) self.canvas = Canvas(self, relief=SUNKEN) self.canvas.config(width=400, height=200) @@ -37,7 +37,7 @@ class ScrolledCanvas(Frame): def set_text(self) -> None: self.canvas.delete('image') - self.canvas.create_text(0, 0, anchor="nw", text=self.info_text, tags="image") + self.canvas.create_text(0, 0, anchor='nw', text=self.info_text, tags='image') self.canvas.config(scrollregion=self.canvas.bbox(ALL)) def set_image(self, content: bytes) -> None: @@ -45,7 +45,7 @@ class ScrolledCanvas(Frame): with BytesIO(content) as f: with Image.open(f) as image: self.image = ImageTk.PhotoImage(image) - self.canvas.create_image(0, 0, anchor="nw", image=self.image, tags='image') + self.canvas.create_image(0, 0, anchor='nw', image=self.image, tags='image') self.canvas.config(scrollregion=self.canvas.bbox(ALL)) def show_image(self, n: int) -> None: @@ -62,23 +62,23 @@ class ScrolledCanvas(Frame): else: self.prev_btn.config(state=NORMAL) self.next_btn.config(state=NORMAL) - self.counter.config(text=f"{self.image_cursor + 1}/{len(self.pages)}") + self.counter.config(text=f'{self.image_cursor + 1}/{len(self.pages)}') self.canvas.yview_moveto(0) self.canvas.xview_moveto(0) def show_in_tk(title, pages, info): root = Tk() - root.geometry("700x700") + root.geometry('700x700') frame = ScrolledCanvas(root) - frame.info_text = "\n".join([f"{key}: {value}" for key, value in info.items()]) + frame.info_text = '\n'.join([f'{key}: {value}' for key, value in info.items()]) frame.pages = pages frame.pack(side=TOP) button_frame = Frame(root) - button_next = Button(button_frame, text="Next", command=lambda: frame.show_image(1)) - button_exit = Button(button_frame, text="Exit", command=root.quit) + button_next = Button(button_frame, text='Next', command=lambda: frame.show_image(1)) + button_exit = Button(button_frame, text='Exit', command=root.quit) counter = Label(button_frame) - button_prev = Button(button_frame, text="Previous", command=lambda: frame.show_image(-1)) + button_prev = Button(button_frame, text='Previous', command=lambda: frame.show_image(-1)) counter.grid(row=0, column=1) button_exit.grid(row=0, column=2) button_next.grid(row=0, column=3) @@ -87,8 +87,8 @@ def show_in_tk(title, pages, info): frame.prev_btn = button_prev frame.counter = counter button_frame.pack(side=BOTTOM) - root.bind('', lambda x: frame.show_image(-1) if button_prev["state"] == NORMAL else True) - root.bind('', lambda x: frame.show_image(1) if button_next["state"] == NORMAL else True) + root.bind('', lambda x: frame.show_image(-1) if button_prev['state'] == NORMAL else True) + root.bind('', lambda x: frame.show_image(1) if button_next['state'] == NORMAL else True) root.bind('', lambda x: root.quit()) frame.show_image(1) root.title(title) diff --git a/cbz/utils.py b/cbz/utils.py index 71d7038..b86977b 100644 --- a/cbz/utils.py +++ b/cbz/utils.py @@ -15,8 +15,7 @@ def _check_type(key: str, value: Any, types: tuple) -> Any: :return: value with new type """ if not isinstance(value, types): - raise ValueError( - f"Unexpected type of {key}, got: {type(value).__name__}, expected: {[i.__name__ for i in types]}") + raise ValueError(f'Unexpected type of {key}, got: {type(value).__name__}, expected: {[i.__name__ for i in types]}') return types[0](value)