From c5772c75e5e31c2a19742ca90a7af62ceeec8ff7 Mon Sep 17 00:00:00 2001 From: lordwelch Date: Sun, 22 May 2022 20:02:49 -0700 Subject: [PATCH 1/2] Cleanup setCheckState Fix word splitting when auto-tagging Remove commented code --- comicapi/filenamelexer.py | 8 ---- comicapi/filenameparser.py | 1 - comicapi/utils.py | 19 --------- comictaggerlib/autotagstartwindow.py | 33 +++++---------- comictaggerlib/cli.py | 1 - comictaggerlib/comicvinecacher.py | 1 - comictaggerlib/crediteditorwindow.py | 5 +-- comictaggerlib/exportwindow.py | 4 +- comictaggerlib/fileselectionlist.py | 1 - comictaggerlib/main.py | 2 +- comictaggerlib/settingswindow.py | 60 ++++++++++------------------ comictaggerlib/taggerwindow.py | 1 - 12 files changed, 35 insertions(+), 101 deletions(-) diff --git a/comicapi/filenamelexer.py b/comicapi/filenamelexer.py index 03de6ec..7fce422 100644 --- a/comicapi/filenamelexer.py +++ b/comicapi/filenamelexer.py @@ -138,13 +138,6 @@ class Lexer: self.backup() - # NextItem returns the next item from the input. - # Called by the parser, not in the lexing goroutine. - # def next_item(self) -> Item: - # item: Item = self.items.get() - # self.lastPos = item.pos - # return item - def scan_number(self) -> bool: digits = "0123456789" @@ -253,7 +246,6 @@ def lex_filename(lex: Lexer) -> Optional[Callable[[Lexer], Optional[Callable]]]: if lex.sbrace_depth < 0: return errorf(lex, "unexpected right brace " + r) elif is_symbol(r): - # L.backup() lex.emit(ItemType.Symbol) else: return errorf(lex, "unrecognized character in action: " + r) diff --git a/comicapi/filenameparser.py b/comicapi/filenameparser.py index efea26a..7fe7c48 100644 --- a/comicapi/filenameparser.py +++ b/comicapi/filenameparser.py @@ -404,7 +404,6 @@ def parse(p: Parser) -> Optional[Callable[[Parser], Optional[Callable]]]: if item.typ == filenamelexer.ItemType.Number: likely_year = False if p.firstItem and p.first_is_alt: - # raise Exception("fuck you") p.alt = True return parse_issue_number diff --git a/comicapi/utils.py b/comicapi/utils.py index b4e19af..83e1764 100644 --- a/comicapi/utils.py +++ b/comicapi/utils.py @@ -34,25 +34,6 @@ class UtilsVars: already_fixed_encoding = False -def get_actual_preferred_encoding() -> str: - preferred_encoding = locale.getpreferredencoding() - if platform.system() == "Darwin": - preferred_encoding = "utf-8" - return preferred_encoding - - -# def fix_output_encoding() -> None: -# if not UtilsVars.already_fixed_encoding: -# # this reads the environment and inits the right locale -# locale.setlocale(locale.LC_ALL, "") - -# # try to make stdout/stderr encodings happy for unicode printing -# preferred_encoding = get_actual_preferred_encoding() -# sys.stdout = codecs.getwriter(preferred_encoding)(sys.stdout) -# sys.stderr = codecs.getwriter(preferred_encoding)(sys.stderr) -# UtilsVars.already_fixed_encoding = True - - def get_recursive_filelist(pathlist: List[str]) -> List[str]: """Get a recursive list of of all files under all path items in the list""" diff --git a/comictaggerlib/autotagstartwindow.py b/comictaggerlib/autotagstartwindow.py index 41937b6..c2f3504 100644 --- a/comictaggerlib/autotagstartwindow.py +++ b/comictaggerlib/autotagstartwindow.py @@ -37,31 +37,18 @@ class AutoTagStartWindow(QtWidgets.QDialog): self.settings = settings - self.cbxSaveOnLowConfidence.setCheckState(QtCore.Qt.CheckState.Unchecked) - self.cbxDontUseYear.setCheckState(QtCore.Qt.CheckState.Unchecked) - self.cbxAssumeIssueOne.setCheckState(QtCore.Qt.CheckState.Unchecked) - self.cbxIgnoreLeadingDigitsInFilename.setCheckState(QtCore.Qt.CheckState.Unchecked) - self.cbxRemoveAfterSuccess.setCheckState(QtCore.Qt.CheckState.Unchecked) - self.cbxSpecifySearchString.setCheckState(QtCore.Qt.CheckState.Unchecked) - self.cbxAutoImprint.setCheckState(QtCore.Qt.CheckState.Unchecked) - self.cbxSplitWords.setCheckState(QtCore.Qt.Unchecked) + self.cbxSpecifySearchString.setChecked(False) + self.cbxSplitWords.setChecked(False) self.leNameLengthMatchTolerance.setText(str(self.settings.id_length_delta_thresh)) self.leSearchString.setEnabled(False) - if self.settings.save_on_low_confidence: - self.cbxSaveOnLowConfidence.setCheckState(QtCore.Qt.CheckState.Checked) - if self.settings.dont_use_year_when_identifying: - self.cbxDontUseYear.setCheckState(QtCore.Qt.CheckState.Checked) - if self.settings.assume_1_if_no_issue_num: - self.cbxAssumeIssueOne.setCheckState(QtCore.Qt.CheckState.Checked) - if self.settings.ignore_leading_numbers_in_filename: - self.cbxIgnoreLeadingDigitsInFilename.setCheckState(QtCore.Qt.CheckState.Checked) - if self.settings.remove_archive_after_successful_match: - self.cbxRemoveAfterSuccess.setCheckState(QtCore.Qt.CheckState.Checked) - if self.settings.wait_and_retry_on_rate_limit: - self.cbxWaitForRateLimit.setCheckState(QtCore.Qt.CheckState.Checked) - if self.settings.auto_imprint: - self.cbxAutoImprint.setCheckState(QtCore.Qt.CheckState.Checked) + self.cbxSaveOnLowConfidence.setChecked(self.settings.save_on_low_confidence) + self.cbxDontUseYear.setChecked(self.settings.dont_use_year_when_identifying) + self.cbxAssumeIssueOne.setChecked(self.settings.assume_1_if_no_issue_num) + self.cbxIgnoreLeadingDigitsInFilename.setChecked(self.settings.ignore_leading_numbers_in_filename) + self.cbxRemoveAfterSuccess.setChecked(self.settings.remove_archive_after_successful_match) + self.cbxWaitForRateLimit.setChecked(self.settings.wait_and_retry_on_rate_limit) + self.cbxAutoImprint.setChecked(self.settings.auto_imprint) nlmt_tip = """ The Name Length Match Tolerance is for eliminating automatic search matches that are too long compared to your series name search. The higher @@ -108,7 +95,7 @@ class AutoTagStartWindow(QtWidgets.QDialog): self.remove_after_success = self.cbxRemoveAfterSuccess.isChecked() self.name_length_match_tolerance = int(self.leNameLengthMatchTolerance.text()) self.wait_and_retry_on_rate_limit = self.cbxWaitForRateLimit.isChecked() - self.splitWords = self.cbxSplitWords.isChecked() + self.split_words = self.cbxSplitWords.isChecked() # persist some settings self.settings.save_on_low_confidence = self.auto_save_on_low diff --git a/comictaggerlib/cli.py b/comictaggerlib/cli.py index 409392b..26f394a 100644 --- a/comictaggerlib/cli.py +++ b/comictaggerlib/cli.py @@ -34,7 +34,6 @@ from comictaggerlib.options import Options from comictaggerlib.resulttypes import IssueResult, MultipleMatch, OnlineMatchResults from comictaggerlib.settings import ComicTaggerSettings -filename_encoding = sys.getfilesystemencoding() logger = logging.getLogger(__name__) diff --git a/comictaggerlib/comicvinecacher.py b/comictaggerlib/comicvinecacher.py index 9382afb..5c083d5 100644 --- a/comictaggerlib/comicvinecacher.py +++ b/comictaggerlib/comicvinecacher.py @@ -311,7 +311,6 @@ class ComicVineCacher: "name": row[1], "count_of_issues": row[3], "start_year": row[4], - # "issues": [], "publisher": {"name": row[2]}, } ) diff --git a/comictaggerlib/crediteditorwindow.py b/comictaggerlib/crediteditorwindow.py index 595f0ed..9454552 100644 --- a/comictaggerlib/crediteditorwindow.py +++ b/comictaggerlib/crediteditorwindow.py @@ -18,7 +18,7 @@ import logging from typing import Any -from PyQt5 import QtCore, QtWidgets, uic +from PyQt5 import QtWidgets, uic from comictaggerlib.settings import ComicTaggerSettings @@ -64,8 +64,7 @@ class CreditEditorWindow(QtWidgets.QDialog): else: self.cbRole.setCurrentIndex(i) - if primary: - self.cbPrimary.setCheckState(QtCore.Qt.CheckState.Checked) + self.cbPrimary.setChecked(primary) self.cbRole.currentIndexChanged.connect(self.role_changed) self.cbRole.editTextChanged.connect(self.role_changed) diff --git a/comictaggerlib/exportwindow.py b/comictaggerlib/exportwindow.py index 62ca378..fdf4e38 100644 --- a/comictaggerlib/exportwindow.py +++ b/comictaggerlib/exportwindow.py @@ -43,8 +43,8 @@ class ExportWindow(QtWidgets.QDialog): self.settings = settings - self.cbxDeleteOriginal.setCheckState(QtCore.Qt.CheckState.Unchecked) - self.cbxAddToList.setCheckState(QtCore.Qt.CheckState.Checked) + self.cbxDeleteOriginal.setChecked(False) + self.cbxAddToList.setChecked(True) self.radioDontCreate.setChecked(True) self.deleteOriginal = False diff --git a/comictaggerlib/fileselectionlist.py b/comictaggerlib/fileselectionlist.py index d539913..cf78629 100644 --- a/comictaggerlib/fileselectionlist.py +++ b/comictaggerlib/fileselectionlist.py @@ -244,7 +244,6 @@ class FileSelectionList(QtWidgets.QWidget): def add_path_item(self, path: str) -> int: path = str(path) path = os.path.abspath(path) - # print "processing", path if self.is_list_dupe(path): return self.get_current_list_row(path) diff --git a/comictaggerlib/main.py b/comictaggerlib/main.py index 547379a..f0ba44c 100755 --- a/comictaggerlib/main.py +++ b/comictaggerlib/main.py @@ -88,7 +88,7 @@ try: from comictaggerlib.taggerwindow import TaggerWindow except ImportError as e: - def show_exception_box(log_msg: str): + def show_exception_box(log_msg: str) -> None: pass logger.error(str(e)) diff --git a/comictaggerlib/settingswindow.py b/comictaggerlib/settingswindow.py index 99a4e87..60b2dd6 100644 --- a/comictaggerlib/settingswindow.py +++ b/comictaggerlib/settingswindow.py @@ -214,8 +214,7 @@ class SettingsWindow(QtWidgets.QDialog): self.leNameLengthDeltaThresh.setText(str(self.settings.id_length_delta_thresh)) self.tePublisherFilter.setPlainText(self.settings.id_publisher_filter) - if self.settings.check_for_new_version: - self.cbxCheckForNewVersion.setCheckState(QtCore.Qt.CheckState.Checked) + self.cbxCheckForNewVersion.setChecked(self.settings.check_for_new_version) self.cbxComplicatedParser.setChecked(self.settings.complicated_parser) self.cbxRemoveC2C.setChecked(self.settings.remove_c2c) @@ -223,52 +222,33 @@ class SettingsWindow(QtWidgets.QDialog): self.cbxRemovePublisher.setChecked(self.settings.remove_publisher) self.switch_parser() - if self.settings.use_series_start_as_volume: - self.cbxUseSeriesStartAsVolume.setCheckState(QtCore.Qt.CheckState.Checked) - if self.settings.clear_form_before_populating_from_cv: - self.cbxClearFormBeforePopulating.setCheckState(QtCore.Qt.CheckState.Checked) - if self.settings.remove_html_tables: - self.cbxRemoveHtmlTables.setCheckState(QtCore.Qt.CheckState.Checked) + self.cbxUseSeriesStartAsVolume.setChecked(self.settings.use_series_start_as_volume) + self.cbxClearFormBeforePopulating.setChecked(self.settings.clear_form_before_populating_from_cv) + self.cbxRemoveHtmlTables.setChecked(self.settings.remove_html_tables) - if self.settings.always_use_publisher_filter: - self.cbxUseFilter.setCheckState(QtCore.Qt.CheckState.Checked) - if self.settings.sort_series_by_year: - self.cbxSortByYear.setCheckState(QtCore.Qt.CheckState.Checked) - if self.settings.exact_series_matches_first: - self.cbxExactMatches.setCheckState(QtCore.Qt.CheckState.Checked) + self.cbxUseFilter.setChecked(self.settings.always_use_publisher_filter) + self.cbxSortByYear.setChecked(self.settings.sort_series_by_year) + self.cbxExactMatches.setChecked(self.settings.exact_series_matches_first) self.leKey.setText(str(self.settings.cv_api_key)) - if self.settings.assume_lone_credit_is_primary: - self.cbxAssumeLoneCreditIsPrimary.setCheckState(QtCore.Qt.CheckState.Checked) - if self.settings.copy_characters_to_tags: - self.cbxCopyCharactersToTags.setCheckState(QtCore.Qt.CheckState.Checked) - if self.settings.copy_teams_to_tags: - self.cbxCopyTeamsToTags.setCheckState(QtCore.Qt.CheckState.Checked) - if self.settings.copy_locations_to_tags: - self.cbxCopyLocationsToTags.setCheckState(QtCore.Qt.CheckState.Checked) - if self.settings.copy_storyarcs_to_tags: - self.cbxCopyStoryArcsToTags.setCheckState(QtCore.Qt.CheckState.Checked) - if self.settings.copy_notes_to_comments: - self.cbxCopyNotesToComments.setCheckState(QtCore.Qt.CheckState.Checked) - if self.settings.copy_weblink_to_comments: - self.cbxCopyWebLinkToComments.setCheckState(QtCore.Qt.CheckState.Checked) - if self.settings.apply_cbl_transform_on_cv_import: - self.cbxApplyCBLTransformOnCVIMport.setCheckState(QtCore.Qt.CheckState.Checked) - if self.settings.apply_cbl_transform_on_bulk_operation: - self.cbxApplyCBLTransformOnBatchOperation.setCheckState(QtCore.Qt.CheckState.Checked) + self.cbxAssumeLoneCreditIsPrimary.setChecked(self.settings.assume_lone_credit_is_primary) + self.cbxCopyCharactersToTags.setChecked(self.settings.copy_characters_to_tags) + self.cbxCopyTeamsToTags.setChecked(self.settings.copy_teams_to_tags) + self.cbxCopyLocationsToTags.setChecked(self.settings.copy_locations_to_tags) + self.cbxCopyStoryArcsToTags.setChecked(self.settings.copy_storyarcs_to_tags) + self.cbxCopyNotesToComments.setChecked(self.settings.copy_notes_to_comments) + self.cbxCopyWebLinkToComments.setChecked(self.settings.copy_weblink_to_comments) + self.cbxApplyCBLTransformOnCVIMport.setChecked(self.settings.apply_cbl_transform_on_cv_import) + self.cbxApplyCBLTransformOnBatchOperation.setChecked(self.settings.apply_cbl_transform_on_bulk_operation) self.leRenameTemplate.setText(self.settings.rename_template) self.leIssueNumPadding.setText(str(self.settings.rename_issue_number_padding)) - if self.settings.rename_use_smart_string_cleanup: - self.cbxSmartCleanup.setCheckState(QtCore.Qt.CheckState.Checked) - if self.settings.rename_extension_based_on_archive: - self.cbxChangeExtension.setCheckState(QtCore.Qt.CheckState.Checked) - if self.settings.rename_move_dir: - self.cbxMoveFiles.setCheckState(QtCore.Qt.CheckState.Checked) + self.cbxSmartCleanup.setChecked(self.settings.rename_use_smart_string_cleanup) + self.cbxChangeExtension.setChecked(self.settings.rename_extension_based_on_archive) + self.cbxMoveFiles.setChecked(self.settings.rename_move_dir) self.leDirectory.setText(self.settings.rename_dir) - if self.settings.rename_strict: - self.cbxRenameStrict.setCheckState(QtCore.Qt.CheckState.Checked) + self.cbxRenameStrict.setChecked(self.settings.rename_strict) def accept(self) -> None: self.rename_test() diff --git a/comictaggerlib/taggerwindow.py b/comictaggerlib/taggerwindow.py index 8a1960f..d7b42e9 100644 --- a/comictaggerlib/taggerwindow.py +++ b/comictaggerlib/taggerwindow.py @@ -255,7 +255,6 @@ Have fun! self.settings.show_disclaimer = not checked if self.settings.check_for_new_version: - # self.checkLatestVersionOnline() pass def sigint_handler(self, *args: Any) -> None: From 8c591a8a3b80974ba6de496ea62a02cf9eac3eb4 Mon Sep 17 00:00:00 2001 From: lordwelch Date: Tue, 24 May 2022 11:44:26 -0700 Subject: [PATCH 2/2] Remove unused imports --- comicapi/utils.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/comicapi/utils.py b/comicapi/utils.py index 83e1764..a64e1c4 100644 --- a/comicapi/utils.py +++ b/comicapi/utils.py @@ -15,11 +15,9 @@ # limitations under the License. import json -import locale import logging import os import pathlib -import platform import re import unicodedata from collections import defaultdict