From f3f48ea958bdb61090705461856ab943c808cf54 Mon Sep 17 00:00:00 2001 From: Timmy Welch Date: Mon, 18 Apr 2022 18:31:06 -0700 Subject: [PATCH] Add the ability to specify a config directory --- comictaggerlib/main.py | 8 ++++---- comictaggerlib/settings.py | 27 +++++++++++++++---------- comictaggerlib/volumeselectionwindow.py | 5 +++++ 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/comictaggerlib/main.py b/comictaggerlib/main.py index 422ac94..8d50793 100755 --- a/comictaggerlib/main.py +++ b/comictaggerlib/main.py @@ -95,6 +95,10 @@ def rotate(handler: logging.handlers.RotatingFileHandler, filename: pathlib.Path def ctmain(): + opts = Options() + opts.parse_cmd_line_args() + SETTINGS = ComicTaggerSettings(opts.config_path) + os.makedirs(ComicTaggerSettings.get_settings_folder() / "logs", exist_ok=True) stream_handler = logging.StreamHandler() stream_handler.setLevel(logging.WARNING) @@ -111,11 +115,7 @@ def ctmain(): format="%(asctime)s | %(name)s | %(levelname)s | %(message)s", datefmt="%Y-%m-%dT%H:%M:%S", ) - opts = Options() - opts.parse_cmd_line_args() - # Need to load setting before anything else - SETTINGS = ComicTaggerSettings() # manage the CV API key if opts.cv_api_key: diff --git a/comictaggerlib/settings.py b/comictaggerlib/settings.py index 0af8402..1eaf0cd 100644 --- a/comictaggerlib/settings.py +++ b/comictaggerlib/settings.py @@ -28,13 +28,16 @@ logger = logging.getLogger(__name__) class ComicTaggerSettings: + folder = "" + @staticmethod def get_settings_folder(): - if platform.system() == "Windows": - folder = os.path.join(os.environ["APPDATA"], "ComicTagger") - else: - folder = os.path.join(os.path.expanduser("~"), ".ComicTagger") - return pathlib.Path(folder) + if not ComicTaggerSettings.folder: + if platform.system() == "Windows": + ComicTaggerSettings.folder = os.path.join(os.environ["APPDATA"], "ComicTagger") + else: + ComicTaggerSettings.folder = os.path.join(os.path.expanduser("~"), ".ComicTagger") + return pathlib.Path(ComicTaggerSettings.folder) @staticmethod def base_dir(): @@ -123,10 +126,9 @@ class ComicTaggerSettings: self.remove_archive_after_successful_match = False self.wait_and_retry_on_rate_limit = False - def __init__(self): + def __init__(self, folder): self.settings_file = "" - self.folder = "" # General Settings self.rar_exe_path = "" self.allow_cbi_in_rar = True @@ -197,12 +199,15 @@ class ComicTaggerSettings: self.wait_and_retry_on_rate_limit = False self.config = configparser.RawConfigParser() - self.folder = ComicTaggerSettings.get_settings_folder() + if folder: + ComicTaggerSettings.folder = pathlib.Path(folder) + else: + ComicTaggerSettings.folder = ComicTaggerSettings.get_settings_folder() - if not os.path.exists(self.folder): - os.makedirs(self.folder) + if not os.path.exists(ComicTaggerSettings.folder): + os.makedirs(ComicTaggerSettings.folder) - self.settings_file = os.path.join(self.folder, "settings") + self.settings_file = os.path.join(ComicTaggerSettings.folder, "settings") # if config file doesn't exist, write one out if not os.path.exists(self.settings_file): diff --git a/comictaggerlib/volumeselectionwindow.py b/comictaggerlib/volumeselectionwindow.py index 79ce9e4..17dcb68 100644 --- a/comictaggerlib/volumeselectionwindow.py +++ b/comictaggerlib/volumeselectionwindow.py @@ -130,6 +130,11 @@ class VolumeSelectionWindow(QtWidgets.QDialog): self.immediate_autoselect = autoselect self.cover_index_list = cover_index_list self.cv_search_results = None + self.ii = None + self.iddialog = None + self.id_thread = None + self.progdialog = None + self.search_thread = None self.use_filter = self.settings.always_use_publisher_filter