Fix folder archiver
Implement supports_comment and is_writable Fix function call in ComicArchive for supports_comment Add a menu option to open a folder as an archive
This commit is contained in:
parent
27f71833b3
commit
548ad4a816
@ -19,7 +19,7 @@ class FolderArchiver(Archiver):
|
||||
|
||||
def get_comment(self) -> str:
|
||||
try:
|
||||
return self.read_file(self.comment_file_name).decode("utf-8")
|
||||
return (self.path / self.comment_file_name).read_text()
|
||||
except OSError:
|
||||
return ""
|
||||
|
||||
@ -28,10 +28,12 @@ class FolderArchiver(Archiver):
|
||||
return self.write_file(self.comment_file_name, comment.encode("utf-8"))
|
||||
return True
|
||||
|
||||
def supports_comment(self) -> bool:
|
||||
return True
|
||||
|
||||
def read_file(self, archive_file: str) -> bytes:
|
||||
try:
|
||||
with open(self.path / archive_file, mode="rb") as f:
|
||||
data = f.read()
|
||||
data = (self.path / archive_file).read_bytes()
|
||||
except OSError as e:
|
||||
logger.error("Error reading folder archive [%s]: %s :: %s", e, self.path, archive_file)
|
||||
raise
|
||||
@ -89,6 +91,9 @@ class FolderArchiver(Archiver):
|
||||
else:
|
||||
return True
|
||||
|
||||
def is_writable(self) -> bool:
|
||||
return True
|
||||
|
||||
def name(self) -> str:
|
||||
return "Folder"
|
||||
|
||||
|
@ -134,7 +134,7 @@ class ComicArchive:
|
||||
return True
|
||||
|
||||
def is_writable_for_style(self, data_style: int) -> bool:
|
||||
return not (data_style == MetaDataStyle.CBI and not self.archiver.supports_comment)
|
||||
return not (data_style == MetaDataStyle.CBI and not self.archiver.supports_comment())
|
||||
|
||||
def is_zip(self) -> bool:
|
||||
return self.archiver.name() == "ZIP"
|
||||
|
@ -91,7 +91,7 @@ def get_recursive_filelist(pathlist: list[str]) -> list[str]:
|
||||
for root, _, files in os.walk(p):
|
||||
for f in files:
|
||||
filelist.append(os.path.join(root, f))
|
||||
else:
|
||||
elif os.path.exists(p):
|
||||
filelist.append(p)
|
||||
|
||||
return filelist
|
||||
|
@ -343,6 +343,10 @@ class TaggerWindow(QtWidgets.QMainWindow):
|
||||
self.actionLoadFolder.setStatusTip("Load folder with comic archives")
|
||||
self.actionLoadFolder.triggered.connect(self.select_folder)
|
||||
|
||||
self.actionOpenFolderAsComic.setShortcut("Ctrl+Shift+Alt+O")
|
||||
self.actionOpenFolderAsComic.setStatusTip("Load folder as a comic archives")
|
||||
self.actionOpenFolderAsComic.triggered.connect(self.select_folder_archive)
|
||||
|
||||
self.actionWrite_Tags.setShortcut("Ctrl+S")
|
||||
self.actionWrite_Tags.setStatusTip("Save tags to comic archive")
|
||||
self.actionWrite_Tags.triggered.connect(self.commit_metadata)
|
||||
@ -438,6 +442,7 @@ class TaggerWindow(QtWidgets.QMainWindow):
|
||||
# ToolBar
|
||||
self.actionLoad.setIcon(QtGui.QIcon(str(graphics_path / "open.png")))
|
||||
self.actionLoadFolder.setIcon(QtGui.QIcon(str(graphics_path / "longbox.png")))
|
||||
self.actionOpenFolderAsComic.setIcon(QtGui.QIcon(str(graphics_path / "open.png")))
|
||||
self.actionWrite_Tags.setIcon(QtGui.QIcon(str(graphics_path / "save.png")))
|
||||
self.actionParse_Filename.setIcon(QtGui.QIcon(str(graphics_path / "parse.png")))
|
||||
self.actionParse_Filename_split_words.setIcon(QtGui.QIcon(str(graphics_path / "parse.png")))
|
||||
@ -987,24 +992,32 @@ class TaggerWindow(QtWidgets.QMainWindow):
|
||||
def select_folder(self) -> None:
|
||||
self.select_file(folder_mode=True)
|
||||
|
||||
def select_folder_archive(self) -> None:
|
||||
dialog = self.file_dialog(folder_mode=True)
|
||||
if dialog.exec():
|
||||
file_list = dialog.selectedFiles()
|
||||
if file_list:
|
||||
self.fileSelectionList.add_path_item(file_list[0])
|
||||
|
||||
def select_file(self, folder_mode: bool = False) -> None:
|
||||
dialog = self.file_dialog(folder_mode=folder_mode)
|
||||
if dialog.exec():
|
||||
file_list = dialog.selectedFiles()
|
||||
self.fileSelectionList.add_path_list(file_list)
|
||||
|
||||
def file_dialog(self, folder_mode: bool = False) -> QtWidgets.QFileDialog:
|
||||
dialog = QtWidgets.QFileDialog(self)
|
||||
if folder_mode:
|
||||
dialog.setFileMode(QtWidgets.QFileDialog.FileMode.Directory)
|
||||
else:
|
||||
archive_filter = "Comic archive files (*.cbz *.zip *.cbr *.rar *.cb7 *.7z)"
|
||||
filters = [archive_filter, "Any files (*)"]
|
||||
dialog.setNameFilters(filters)
|
||||
dialog.setFileMode(QtWidgets.QFileDialog.FileMode.ExistingFiles)
|
||||
|
||||
if self.config[0].internal_last_opened_folder is not None:
|
||||
dialog.setDirectory(self.config[0].internal_last_opened_folder)
|
||||
|
||||
if not folder_mode:
|
||||
archive_filter = "Comic archive files (*.cbz *.zip *.cbr *.rar *.cb7 *.7z)"
|
||||
filters = [archive_filter, "Any files (*)"]
|
||||
dialog.setNameFilters(filters)
|
||||
|
||||
if dialog.exec():
|
||||
file_list = dialog.selectedFiles()
|
||||
self.fileSelectionList.add_path_list(file_list)
|
||||
return dialog
|
||||
|
||||
def auto_identify_search(self) -> None:
|
||||
if self.comic_archive is None:
|
||||
|
@ -1156,7 +1156,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1096</width>
|
||||
<height>30</height>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuComicTagger">
|
||||
@ -1180,6 +1180,7 @@
|
||||
</widget>
|
||||
<addaction name="actionLoad"/>
|
||||
<addaction name="actionLoadFolder"/>
|
||||
<addaction name="actionOpenFolderAsComic"/>
|
||||
<addaction name="actionWrite_Tags"/>
|
||||
<addaction name="actionAutoTag"/>
|
||||
<addaction name="actionCopyTags"/>
|
||||
@ -1444,6 +1445,11 @@
|
||||
<string>perform a literal search on the series and return the first 50 results</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionOpenFolderAsComic">
|
||||
<property name="text">
|
||||
<string>Open Folder as Comic</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
|
Loading…
Reference in New Issue
Block a user