Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue #198 #210

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AniList(IMetadataSource):
_log = logging.getLogger()
# Map the Role from API to the ComicInfo tags to write
person_mapper = {}
_HOW_METADATA_MAPS_TOOLTIP = "How metadata field will map to ComicInfo fields"
_HOW_METADATA_MAPS_TOOLTIP = "How metadata field will map to ComicInfo fields"
romaji_as_series = Settings().get(name, AniListSetting.SeriesTitleLanguage)

def init_settings(self):
Expand Down
28 changes: 23 additions & 5 deletions MangaManager/src/Common/LoadedComicInfo/LoadedComicInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ def get_template_filename(self, input_template: str) -> str|None:
:return: None if there's a missing key in the template
"""
try:
return input_template.format_map(self.get_template_values()).replace(" ", " ")
illegal_chars = ('<', '>', ':', '"', '\\','/', '|', "?", '*')
path_split = input_template.format_map(self.get_template_values()).replace(" ", " ").split('/')
sanitized_path_split = []
for path_component in path_split:
sanitized_path_split.append("".join(ch for ch in path_component if ch.isalnum() or ch not in illegal_chars).strip())
return "/".join(sanitized_path_split)

except KeyError as e:
logger.error(f"Could not get {list(e.args)} keys when filling template values")
return None
Expand Down Expand Up @@ -178,10 +184,22 @@ def _process(self, write_metadata=False, do_convert_to_webp=False, **_):
try:
with ArchiveFile(self.file_path, 'r') as zin:
assert initial_file_count == len(zin.namelist())
os.remove(self.file_path)
os.rename(tmpname, self.file_path)
logger.debug(f"[{'Processing':13s}] Successfully deleted old file and named tempfile as the old file",
extra=self._logging_extra)
# If move_on_update setting is True, we should move the temp file to new location, then delete original file.
if Settings().get("Main", "move_on_update") == True:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you help me understand this new code and why it would be used?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry! I thought the pull was matched to commit not pulling HEAD. Was adding file management functionality on my fork to aid in library management. Lemme close this out and make sure any file management code is removed.

template_str = Settings().get("Main", "move_to_template")
library_path = Settings().get("Main", "library_path")
original_ext = self.file_path.split(".")[-1]
new_file_name = self.get_template_filename(template_str)
new_file_path = f'{library_path}/{new_file_name}.{original_ext}'
os.renames(tmpname, new_file_path)
os.remove(self.file_path)
logger.debug(f"[{'Processing':13s}] Moved file to new template filename under library",
extra=self._logging_extra)
else:
os.remove(self.file_path)
os.rename(tmpname, self.file_path)
logger.debug(f"[{'Processing':13s}] Successfully deleted old file and named tempfile as the old file",
extra=self._logging_extra)
# If we fail to delete original file we delete temp file effecively aborting the metadata update
except PermissionError:
logger.exception(f"[{'Processing':13s}] Permission error. Aborting and clearing temp files",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def template_validation(key_list):
validate=lambda key, value: '[' + ", ".join(template_validation(
re.findall(r'\{(\w+)\}', value))) + "] are not valid tags" if len(
template_validation(re.findall(r'\{(\w+)\}', value))) != 0 else ""),
"move_on_update": SettingControl("move_on_update", "Rename on update",
SettingControlType.Bool, True,
"If enabled, files will be renamed according to the Rename Filename template under the Library Path"),
"clean_ui_on_drag_drop": SettingControl("remove_old_selection_on_drag_drop","Clean previous selection\non drag and drop", SettingControlType.Bool, True, "After you drag and drop, previous selected files will be discarded")
},
SettingHeading.WebpConverter: {
Expand Down
4 changes: 2 additions & 2 deletions MangaManager/src/Settings/SettingsDefault.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class SettingHeading(StrEnum):
{"create_backup_comicinfo": True},
# {"selected_layout": "default"},
{"move_to_template": ""},
{"remove_old_selection_on_drag_drop":True}

{"remove_old_selection_on_drag_drop":True},
{"move_on_update": False}
],
SettingHeading.WebpConverter: [
{"default_base_path": ""},
Expand Down