diff --git a/comictaggerlib/ctoptions/cmdline.py b/comictaggerlib/ctoptions/cmdline.py index 4d9d413..6d872ed 100644 --- a/comictaggerlib/ctoptions/cmdline.py +++ b/comictaggerlib/ctoptions/cmdline.py @@ -299,8 +299,8 @@ def validate_commandline_options(options: settngs.Config[settngs.Values], parser if ( options[0].commands_only_set_cv_key - and options[0].comicvine_cv_api_key is None - and options[0].comicvine_cv_url is None + and options[0].talker_comicvine_cv_api_key is None + and options[0].talker_comicvine_cv_url is None ): parser.exit(message="Key not given!\n", status=1) diff --git a/comictaggerlib/ctoptions/talker_plugins.py b/comictaggerlib/ctoptions/talker_plugins.py index c7c959f..727cf18 100644 --- a/comictaggerlib/ctoptions/talker_plugins.py +++ b/comictaggerlib/ctoptions/talker_plugins.py @@ -13,6 +13,6 @@ logger = logging.getLogger(__name__) def register_talker_settings(parser: settngs.Manager, plugins: Mapping[str, ComicTalker]) -> None: for talker_name, talker in plugins.items(): try: - parser.add_group(talker_name, talker.register_settings, False) + parser.add_group("talker_" + talker_name, talker.register_settings, False) except Exception: logger.exception("Failed to register settings for %s", talker_name) diff --git a/comictaggerlib/main.py b/comictaggerlib/main.py index 01e2ee1..d6afa07 100644 --- a/comictaggerlib/main.py +++ b/comictaggerlib/main.py @@ -123,13 +123,13 @@ class App: def initialize_talkers(self) -> None: # Apply talker settings from config file - try: - for talker_name, talker in self.talker_plugins.items(): - ct_api.set_talker_settings(talker, self.options[0][talker_name]) - except Exception as e: - # Remove talker as we failed to apply the settings - del self.talker_plugins[e.source] # type: ignore[attr-defined] - logger.exception("Failed to initialize talker settings. Error %s", str(e)) + for talker_name, talker in list(self.talker_plugins.items()): + try: + talker.parse_settings(self.options[0]["talker_" + talker_name]) + except Exception as e: + # Remove talker as we failed to apply the settings + del self.talker_plugins[talker_name] # type: ignore[attr-defined] + logger.exception("Failed to initialize talker settings. Error %s", e) def main(self) -> None: assert self.options is not None @@ -149,14 +149,17 @@ class App: self.options[0].runtime_no_gui = True logger.warning("PyQt5 is not available. ComicTagger is limited to command-line mode.") - # TODO Have option to save passed in config options and quit? + if self.options[0].commands_only_set_cv_key: + if self.config_load_success: + print("Key set") # noqa: T201 + return try: talker_api = self.talker_plugins[self.options[0].talkers_source] - except Exception as e: - logger.exception(f"Unable to load talker {self.options[0].talkers_source}. Error: {str(e)}") + except Exception: + logger.exception(f"Unable to load talker {self.options[0].talkers_source}") # TODO error True can be changed to False after the talker settings menu generation is in - error = (f"Unable to load talker {self.options[0].talkers_source}. Error: {str(e)}", True) + error = (f"Unable to load talker {self.options[0].talkers_source}", True) if not self.config_load_success: error = ( diff --git a/comictaggerlib/settingswindow.py b/comictaggerlib/settingswindow.py index 07b1a05..e866562 100644 --- a/comictaggerlib/settingswindow.py +++ b/comictaggerlib/settingswindow.py @@ -285,16 +285,16 @@ class SettingsWindow(QtWidgets.QDialog): self.cbxRemovePublisher.setChecked(self.options[0].filename_remove_publisher) self.switch_parser() - self.cbxUseSeriesStartAsVolume.setChecked(self.options[0].comicvine_cv_use_series_start_as_volume) + self.cbxUseSeriesStartAsVolume.setChecked(self.options[0].talker_comicvine_cv_use_series_start_as_volume) self.cbxClearFormBeforePopulating.setChecked(self.options[0].talkers_clear_form_before_populating) - self.cbxRemoveHtmlTables.setChecked(self.options[0].comicvine_cv_remove_html_tables) + self.cbxRemoveHtmlTables.setChecked(self.options[0].talker_comicvine_cv_remove_html_tables) self.cbxUseFilter.setChecked(self.options[0].talkers_always_use_publisher_filter) self.cbxSortByYear.setChecked(self.options[0].talkers_sort_series_by_year) self.cbxExactMatches.setChecked(self.options[0].talkers_exact_series_matches_first) - self.leKey.setText(self.options[0].comicvine_cv_api_key) - self.leURL.setText(self.options[0].comicvine_cv_url) + self.leKey.setText(self.options[0].talker_comicvine_cv_api_key) + self.leURL.setText(self.options[0].talker_comicvine_cv_url) self.cbxAssumeLoneCreditIsPrimary.setChecked(self.options[0].cbl_assume_lone_credit_is_primary) self.cbxCopyCharactersToTags.setChecked(self.options[0].cbl_copy_characters_to_tags) @@ -400,21 +400,21 @@ class SettingsWindow(QtWidgets.QDialog): self.options[0].filename_remove_fcbd = self.cbxRemoveFCBD.isChecked() self.options[0].filename_remove_publisher = self.cbxRemovePublisher.isChecked() - self.options[0].comicvine_cv_use_series_start_as_volume = self.cbxUseSeriesStartAsVolume.isChecked() + self.options[0].talker_comicvine_cv_use_series_start_as_volume = self.cbxUseSeriesStartAsVolume.isChecked() self.options[0].talkers_clear_form_before_populating = self.cbxClearFormBeforePopulating.isChecked() - self.options[0].comicvine_cv_remove_html_tables = self.cbxRemoveHtmlTables.isChecked() + self.options[0].talker_comicvine_cv_remove_html_tables = self.cbxRemoveHtmlTables.isChecked() self.options[0].talkers_always_use_publisher_filter = self.cbxUseFilter.isChecked() self.options[0].talkers_sort_series_by_year = self.cbxSortByYear.isChecked() self.options[0].talkers_exact_series_matches_first = self.cbxExactMatches.isChecked() if self.leKey.text().strip(): - self.options[0].comicvine_cv_api_key = self.leKey.text().strip() - self.talker_api.api_key = self.options[0].comicvine_cv_api_key + self.options[0].talker_comicvine_cv_api_key = self.leKey.text().strip() + self.talker_api.api_key = self.options[0].talker_comicvine_cv_api_key if self.leURL.text().strip(): - self.options[0].comicvine_cv_url = self.leURL.text().strip() - self.talker_api.api_url = self.options[0].comicvine_cv_url + self.options[0].talker_comicvine_cv_url = self.leURL.text().strip() + self.talker_api.api_url = self.options[0].talker_comicvine_cv_url self.options[0].cbl_assume_lone_credit_is_primary = self.cbxAssumeLoneCreditIsPrimary.isChecked() self.options[0].cbl_copy_characters_to_tags = self.cbxCopyCharactersToTags.isChecked() diff --git a/comictalker/comictalkerapi.py b/comictalker/comictalkerapi.py index 17f5375..79bab76 100644 --- a/comictalker/comictalkerapi.py +++ b/comictalker/comictalkerapi.py @@ -18,7 +18,6 @@ from __future__ import annotations import logging import pathlib from collections.abc import Mapping -from typing import Any import comictalker.talkers.comicvine from comictalker.talkerbase import ComicTalker, TalkerError @@ -26,16 +25,6 @@ from comictalker.talkerbase import ComicTalker, TalkerError logger = logging.getLogger(__name__) -def set_talker_settings(talker: ComicTalker, settings: dict[str, Any]) -> None: - try: - talker.parse_settings(settings) - except Exception as e: - logger.exception( - f"Failed to set talker settings for {talker.source_details.name}, will use defaults. Error: {str(e)}", - ) - raise TalkerError(source=talker.source_details.name, code=4, desc="Could not apply talker settings") - - def get_talkers(version: str, cache: pathlib.Path) -> Mapping[str, ComicTalker]: """Returns all comic talker instances""" # TODO separate PR will bring talkers in via entry points. TalkerError etc. source will then be a var diff --git a/comictalker/talkerbase.py b/comictalker/talkerbase.py index 36d5f3f..94daf64 100644 --- a/comictalker/talkerbase.py +++ b/comictalker/talkerbase.py @@ -151,10 +151,12 @@ class ComicTalker: def register_settings(self, parser: settngs.Manager) -> None: """Allows registering settings using the settngs package with an argparse like interface""" + return None def parse_settings(self, settings: dict[str, Any]) -> None: """settings is a dictionary of options defined in register_settings. It is only guaranteed that the settings defined in register_settings will be present.""" + return None def check_api_key(self, key: str, url: str) -> bool: """