standardize quotes

This commit is contained in:
hyugogirubato
2024-07-07 18:49:43 +02:00
parent 7b85489bd0
commit 9902a7872d
5 changed files with 105 additions and 106 deletions
+7 -7
View File
@@ -23,7 +23,7 @@ class ComicInfo(ComicModel):
def dumps(self) -> dict: def dumps(self) -> dict:
return utils.dumps(self._get() | { 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) 'PageCount': len(self.__pages)
}) })
@@ -65,7 +65,7 @@ class ComicInfo(ComicModel):
with Path(path).open(mode='rb') as f: with Path(path).open(mode='rb') as f:
with zipfile.ZipFile(f, 'r', zipfile.ZIP_STORED) as zip_file: with zipfile.ZipFile(f, 'r', zipfile.ZIP_STORED) as zip_file:
xml_file = zip_file.open(xml_name) 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() xml_file.close()
return info return info
@@ -87,22 +87,22 @@ class ComicInfo(ComicModel):
Save changes to opened from file or already saved to file comic Save changes to opened from file or already saved to file comic
:return: :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) self.to_cbz(self._filepath)
@staticmethod @staticmethod
def __unpack(file_path: Path) -> dict: def __unpack(file_path: Path) -> dict:
with zipfile.ZipFile(file_path, 'r', zipfile.ZIP_STORED) as zip_file: with zipfile.ZipFile(file_path, 'r', zipfile.ZIP_STORED) as zip_file:
_files = zip_file.namelist() _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) 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() xml_file.close()
_files.remove(xml_name) _files.remove(xml_name)
info["pages"] = list() info['pages'] = list()
for filename in _files: for filename in _files:
page_file = zip_file.open(filename) 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() page_file.close()
return info return info
+50 -50
View File
@@ -1,7 +1,7 @@
from enum import Enum from enum import Enum
from langcodes import Language from langcodes import Language
xml_name = "ComicInfo.xml" xml_name = 'ComicInfo.xml'
class YesNo(Enum): class YesNo(Enum):
@@ -119,58 +119,58 @@ class ValidLanguage(str):
FIELDS = ( FIELDS = (
# model: (key, xml key): (variable name, (expected type, second expected type,...)) # model: (key, xml key): (variable name, (expected type, second expected type,...))
# in case of multiple expected formats, value cast to first type in tuple # in case of multiple expected formats, value cast to first type in tuple
(("title", "Title"), ("title", (str,))), (('title', 'Title'), ('title', (str,))),
(("series", "Series"), ("series", (str,))), (('series', 'Series'), ('series', (str,))),
(("number", "Number"), ("number", (str, int, float))), (('number', 'Number'), ('number', (str, int, float))),
(("count", "Count"), ("count", (int,))), (('count', 'Count'), ('count', (int,))),
(("volume", "Volume"), ("volume", (int,))), (('volume', 'Volume'), ('volume', (int,))),
(("alternate_series", "AlternateSeries"), ("alternate_series", (str,))), (('alternate_series', 'AlternateSeries'), ('alternate_series', (str,))),
(("alternate_number", "AlternateNumber"), ("alternate_number", (str, int, float))), (('alternate_number', 'AlternateNumber'), ('alternate_number', (str, int, float))),
(("alternate_count", "AlternateCount"), ("alternate_count", (int,))), (('alternate_count', 'AlternateCount'), ('alternate_count', (int,))),
(("summary", "Summary"), ("summary", (str,))), (('summary', 'Summary'), ('summary', (str,))),
(("notes", "Notes"), ("notes", (str,))), (('notes', 'Notes'), ('notes', (str,))),
(("year", "Year"), ("year", (int,))), (('year', 'Year'), ('year', (int,))),
(("month", "Month"), ("month", (int,))), (('month', 'Month'), ('month', (int,))),
(("day", "Day"), ("day", (int,))), (('day', 'Day'), ('day', (int,))),
(("writer", "Writer"), ("writer", (str,))), (('writer', 'Writer'), ('writer', (str,))),
(("penciller", "Penciller"), ("penciller", (str,))), (('penciller', 'Penciller'), ('penciller', (str,))),
(("inker", "Inker"), ("inker", (str,))), (('inker', 'Inker'), ('inker', (str,))),
(("colorist", "Colorist"), ("colorist", (str,))), (('colorist', 'Colorist'), ('colorist', (str,))),
(("letterer", "Letterer"), ("letterer", (str,))), (('letterer', 'Letterer'), ('letterer', (str,))),
(("cover_artist", "CoverArtist"), ("cover_artist", (str,))), (('cover_artist', 'CoverArtist'), ('cover_artist', (str,))),
(("editor", "Editor"), ("editor", (str,))), (('editor', 'Editor'), ('editor', (str,))),
(("translator", "Translator"), ("translator", (str,))), (('translator', 'Translator'), ('translator', (str,))),
(("publisher", "Publisher"), ("publisher", (str,))), (('publisher', 'Publisher'), ('publisher', (str,))),
(("imprint", "Imprint"), ("imprint", (str,))), (('imprint', 'Imprint'), ('imprint', (str,))),
(("genre", "Genre"), ("genre", (str,))), (('genre', 'Genre'), ('genre', (str,))),
(("tags", "Tags"), ("tags", (str,))), (('tags', 'Tags'), ('tags', (str,))),
(("web", "Web"), ("web", (str,))), (('web', 'Web'), ('web', (str,))),
(("format", "Format"), ("format", (Format, str))), (('format', 'Format'), ('format', (Format, str))),
(("ean", "EAN"), ("ean", (str,))), (('ean', 'EAN'), ('ean', (str,))),
(("black_white", "BlackAndWhite"), ("black_white", (YesNo, str))), (('black_white', 'BlackAndWhite'), ('black_white', (YesNo, str))),
(("manga", "Manga"), ("manga", (Manga, str))), (('manga', 'Manga'), ('manga', (Manga, str))),
(("characters", "Characters"), ("characters", (str,))), (('characters', 'Characters'), ('characters', (str,))),
(("teams", "Teams"), ("teams", (str,))), (('teams', 'Teams'), ('teams', (str,))),
(("locations", "Locations"), ("locations", (str,))), (('locations', 'Locations'), ('locations', (str,))),
(("scan_information", "ScanInformation"), ("scan_information", (str,))), (('scan_information', 'ScanInformation'), ('scan_information', (str,))),
(("story_arc", "StoryArc"), ("story_arc", (str,))), (('story_arc', 'StoryArc'), ('story_arc', (str,))),
(("story_arc_number", "StoryArcNumber"), ("story_arc_number", (str,))), (('story_arc_number', 'StoryArcNumber'), ('story_arc_number', (str,))),
(("series_group", "SeriesGroup"), ("series_group", (str,))), (('series_group', 'SeriesGroup'), ('series_group', (str,))),
(("age_rating", "AgeRating"), ("age_rating", (AgeRating, str))), (('age_rating', 'AgeRating'), ('age_rating', (AgeRating, str))),
(("main_character_or_team", "MainCharacterOrTeam"), ("main_character_or_team", (str,))), (('main_character_or_team', 'MainCharacterOrTeam'), ('main_character_or_team', (str,))),
(("review", "Review"), ("review", (str,))), (('review', 'Review'), ('review', (str,))),
(("language_iso", "LanguageISO"), ("language_iso", (ValidLanguage, str))), (('language_iso', 'LanguageISO'), ('language_iso', (ValidLanguage, str))),
(("community_rating", "CommunityRating"), ("community_rating", (ValidRating, float, int, str))), (('community_rating', 'CommunityRating'), ('community_rating', (ValidRating, float, int, str))),
) )
PAGE_FIELDS = ( PAGE_FIELDS = (
# model: (key, xml key): (variable name, (expected type, second expected type,...)) # model: (key, xml key): (variable name, (expected type, second expected type,...))
# in case of multiple expected formats, value cast to first type in tuple # in case of multiple expected formats, value cast to first type in tuple
(("type", "Type"), ("type", (PageType, str))), (('type', 'Type'), ('type', (PageType, str))),
(("double", "DoublePage"), ("double", (bool,))), (('double', 'DoublePage'), ('double', (bool,))),
(("key", "Key"), ("key", (str,))), (('key', 'Key'), ('key', (str,))),
(("bookmark", "Bookmark"), ("bookmark", (str,))), (('bookmark', 'Bookmark'), ('bookmark', (str,))),
(("image_size", "ImageSize"), ("_image_size", (int,))), (('image_size', 'ImageSize'), ('_image_size', (int,))),
(("image_width", "ImageWidth"), ("_image_width", (int,))), (('image_width', 'ImageWidth'), ('_image_width', (int,))),
(("image_height", "ImageHeight"), ("_image_height", (int,))), (('image_height', 'ImageHeight'), ('_image_height', (int,))),
) )
+34 -34
View File
@@ -3,49 +3,49 @@ from cbz.utils import _get, _set
class ComicModel: class ComicModel:
title: str = "" title: str = ''
series: str = "" series: str = ''
number: str = "" number: str = ''
count: int = -1 count: int = -1
volume: int = -1 volume: int = -1
alternate_series: str = "" alternate_series: str = ''
alternate_number: str = "" alternate_number: str = ''
alternate_count: int = -1 alternate_count: int = -1
summary: str = "" summary: str = ''
notes: str = "" notes: str = ''
year: int = -1 year: int = -1
month: int = -1 month: int = -1
day: int = -1 day: int = -1
writer: str = "" writer: str = ''
penciller: str = "" penciller: str = ''
inker: str = "" inker: str = ''
colorist: str = "" colorist: str = ''
letterer: str = "" letterer: str = ''
cover_artist: str = "" cover_artist: str = ''
editor: str = "" editor: str = ''
translator: str = "" translator: str = ''
publisher: str = "" publisher: str = ''
imprint: str = "" imprint: str = ''
genre: str = "" genre: str = ''
tags: str = "" tags: str = ''
web: str = "" web: str = ''
language_iso: str = "" language_iso: str = ''
format: Format = Format.UNKNOWN format: Format = Format.UNKNOWN
ean: str = "" ean: str = ''
black_white: YesNo = YesNo.UNKNOWN black_white: YesNo = YesNo.UNKNOWN
manga: Manga = Manga.UNKNOWN manga: Manga = Manga.UNKNOWN
characters: str = "" characters: str = ''
teams: str = "" teams: str = ''
locations: str = "" locations: str = ''
scan_information: str = "" scan_information: str = ''
story_arc: str = "" story_arc: str = ''
story_arc_number: str = "" story_arc_number: str = ''
series_group: str = "" series_group: str = ''
age_rating: AgeRating = AgeRating.UNKNOWN age_rating: AgeRating = AgeRating.UNKNOWN
community_rating: int = -1 community_rating: int = -1
main_character_or_team: str = "" main_character_or_team: str = ''
review: str = "" review: str = ''
_filepath: str = "" _filepath: str = ''
def __init__(self, kwargs: dict): def __init__(self, kwargs: dict):
_set(self, FIELDS, kwargs) _set(self, FIELDS, kwargs)
@@ -60,8 +60,8 @@ class PageModel:
type: PageType = PageType.STORY type: PageType = PageType.STORY
double: bool = False double: bool = False
_image_size: int = 0 _image_size: int = 0
key: str = "" key: str = ''
bookmark: str = "" bookmark: str = ''
_image_width: int = 0 _image_width: int = 0
_image_height: int = 0 _image_height: int = 0
+12 -12
View File
@@ -6,7 +6,7 @@ from PIL import ImageTk, Image
class ScrolledCanvas(Frame): class ScrolledCanvas(Frame):
image_cursor: int = -2 image_cursor: int = -2
info_text: str = "" info_text: str = ''
pages = list() pages = list()
next_btn = None next_btn = None
prev_btn = None prev_btn = None
@@ -15,7 +15,7 @@ class ScrolledCanvas(Frame):
def __init__(self, parent=None): def __init__(self, parent=None):
Frame.__init__(self, parent) Frame.__init__(self, parent)
self.master.title("Spectrogram Viewer") self.master.title('Spectrogram Viewer')
self.pack(expand=YES, fill=BOTH) self.pack(expand=YES, fill=BOTH)
self.canvas = Canvas(self, relief=SUNKEN) self.canvas = Canvas(self, relief=SUNKEN)
self.canvas.config(width=400, height=200) self.canvas.config(width=400, height=200)
@@ -37,7 +37,7 @@ class ScrolledCanvas(Frame):
def set_text(self) -> None: def set_text(self) -> None:
self.canvas.delete('image') 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)) self.canvas.config(scrollregion=self.canvas.bbox(ALL))
def set_image(self, content: bytes) -> None: def set_image(self, content: bytes) -> None:
@@ -45,7 +45,7 @@ class ScrolledCanvas(Frame):
with BytesIO(content) as f: with BytesIO(content) as f:
with Image.open(f) as image: with Image.open(f) as image:
self.image = ImageTk.PhotoImage(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)) self.canvas.config(scrollregion=self.canvas.bbox(ALL))
def show_image(self, n: int) -> None: def show_image(self, n: int) -> None:
@@ -62,23 +62,23 @@ class ScrolledCanvas(Frame):
else: else:
self.prev_btn.config(state=NORMAL) self.prev_btn.config(state=NORMAL)
self.next_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.yview_moveto(0)
self.canvas.xview_moveto(0) self.canvas.xview_moveto(0)
def show_in_tk(title, pages, info): def show_in_tk(title, pages, info):
root = Tk() root = Tk()
root.geometry("700x700") root.geometry('700x700')
frame = ScrolledCanvas(root) 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.pages = pages
frame.pack(side=TOP) frame.pack(side=TOP)
button_frame = Frame(root) button_frame = Frame(root)
button_next = Button(button_frame, text="Next", command=lambda: frame.show_image(1)) button_next = Button(button_frame, text='Next', command=lambda: frame.show_image(1))
button_exit = Button(button_frame, text="Exit", command=root.quit) button_exit = Button(button_frame, text='Exit', command=root.quit)
counter = Label(button_frame) 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) counter.grid(row=0, column=1)
button_exit.grid(row=0, column=2) button_exit.grid(row=0, column=2)
button_next.grid(row=0, column=3) button_next.grid(row=0, column=3)
@@ -87,8 +87,8 @@ def show_in_tk(title, pages, info):
frame.prev_btn = button_prev frame.prev_btn = button_prev
frame.counter = counter frame.counter = counter
button_frame.pack(side=BOTTOM) button_frame.pack(side=BOTTOM)
root.bind('<Left>', lambda x: frame.show_image(-1) if button_prev["state"] == NORMAL else True) root.bind('<Left>', lambda x: frame.show_image(-1) if button_prev['state'] == NORMAL else True)
root.bind('<Right>', lambda x: frame.show_image(1) if button_next["state"] == NORMAL else True) root.bind('<Right>', lambda x: frame.show_image(1) if button_next['state'] == NORMAL else True)
root.bind('<Escape>', lambda x: root.quit()) root.bind('<Escape>', lambda x: root.quit())
frame.show_image(1) frame.show_image(1)
root.title(title) root.title(title)
+1 -2
View File
@@ -15,8 +15,7 @@ def _check_type(key: str, value: Any, types: tuple) -> Any:
:return: value with new type :return: value with new type
""" """
if not isinstance(value, types): if not isinstance(value, types):
raise ValueError( raise ValueError(f'Unexpected type of {key}, got: {type(value).__name__}, expected: {[i.__name__ for i in types]}')
f"Unexpected type of {key}, got: {type(value).__name__}, expected: {[i.__name__ for i in types]}")
return types[0](value) return types[0](value)