From 69eea899efb4dcd2ef9230f4cdbe42815acb7e6d Mon Sep 17 00:00:00 2001 From: Prinz23 Date: Mon, 12 Aug 2024 21:33:28 +0100 Subject: [PATCH] Change add CONFIG_LOADED var to prevent saving config.ini before it's fully loaded Change providers to save config.ini if needed at the end of init stage 1 --- CHANGES.md | 8 +++++++- sickgear/__init__.py | 17 ++++++++++++++--- sickgear/providers/generic.py | 19 ++++++++++++++++--- sickgear/providers/immortalseed.py | 2 +- sickgear/providers/speedcd.py | 2 +- 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index af61f176..8916afe8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,10 @@ -### 3.32.6 (2024-08-12 17:10:00 UTC) +### 3.32.7 (2024-08-13 11:30:00 UTC) + +* Change to prevent saving config.ini before it's fully loaded +* Change login form to be more password manager friendly + + +### 3.32.6 (2024-08-12 17:10:00 UTC) * Fix saving config.ini after restart and startup diff --git a/sickgear/__init__.py b/sickgear/__init__.py index f47b14de..1f7eee64 100644 --- a/sickgear/__init__.py +++ b/sickgear/__init__.py @@ -76,6 +76,7 @@ CFG = None # type: ConfigObj CONFIG_FILE = '' CONFIG_VERSION = None CONFIG_OLD = None +CONFIG_LOADED = False # Default encryption version (0 for None) ENCRYPTION_VERSION = 0 @@ -671,7 +672,7 @@ def init_stage_1(console_logging): WEB_HOST, WEB_ROOT, ACTUAL_CACHE_DIR, CACHE_DIR, ZONEINFO_DIR, ADD_SHOWS_WO_DIR, ADD_SHOWS_METALANG, \ CREATE_MISSING_SHOW_DIRS, SHOW_DIRS_WITH_DOTS, \ RECENTSEARCH_STARTUP, NAMING_FORCE_FOLDERS, SOCKET_TIMEOUT, DEBUG, TVINFO_DEFAULT, \ - CONFIG_FILE, CONFIG_VERSION, CONFIG_OLD, \ + CONFIG_FILE, CONFIG_VERSION, CONFIG_OLD, CONFIG_LOADED, \ REMOVE_FILENAME_CHARS, IMPORT_DEFAULT_CHECKED_SHOWS, WANTEDLIST_CACHE, MODULE_UPDATE_STRING, EXT_UPDATES # Add Show Search global RESULTS_SORTBY @@ -1479,6 +1480,7 @@ def init_stage_1(console_logging): header = callable(getattr(cur_provider, '_init_api', False)) and False is cur_provider._init_api() \ and header or {} cur_provider.headers.update(header) + update_config |= cur_provider.should_save_config() # current commit hash CUR_COMMIT_HASH = check_setting_str(CFG, 'General', 'cur_commit_hash', '') @@ -1510,6 +1512,10 @@ def init_stage_1(console_logging): # Get expected config version CONFIG_VERSION = max(ConfigMigrator(CFG).migration_names) + + # we have fully loaded all config settings into vars + CONFIG_LOADED = True + if update_config: _save_config(force=True) @@ -1896,7 +1902,9 @@ def save_config(force=False): :param force: force save config even if unchanged """ - global config_events + global config_events, CONFIG_LOADED + if not CONFIG_LOADED: + return # use queue if it's available, otherwise, call save_config directly hasattr(config_events, 'put') and config_events.put(force) or _save_config(force) @@ -1904,7 +1912,10 @@ def save_config(force=False): def _save_config(force=False, **kwargs): # type: (bool, ...) -> None - global CONFIG_OLD + global CONFIG_OLD, CONFIG_LOADED + if not CONFIG_LOADED: + return + new_config = ConfigObj() new_config.filename = CONFIG_FILE diff --git a/sickgear/providers/generic.py b/sickgear/providers/generic.py index e35154c3..3f088120 100644 --- a/sickgear/providers/generic.py +++ b/sickgear/providers/generic.py @@ -275,6 +275,19 @@ class GenericProvider(object): self.scene_rej_nuked = False # type: bool self.scene_nuked_active = False # type: bool + self._save_config = False # type: bool + + + def save_main_config(self): + self._save_config = True + sickgear.save_config() + + def should_save_config(self): + # type: (...) -> bool + _s_c = self._save_config + self._save_config = False + return _s_c + def _load_fail_values(self): if hasattr(sickgear, 'DATA_DIR'): my_db = db.DBConnection('cache.db') @@ -1957,7 +1970,7 @@ class TorrentProvider(GenericProvider): if last_url != cur_url or (expire and not (expire > int(time.time()))): sickgear.PROVIDER_HOMES[self.get_id()] = (cur_url, int(time.time()) + (60*60)) - sickgear.save_config() + self.save_main_config() return cur_url seen_attr = 'PROVIDER_SEEN' @@ -1975,7 +1988,7 @@ class TorrentProvider(GenericProvider): if not hasattr(self, 'url_api'): self.urls = {} sickgear.PROVIDER_HOMES[self.get_id()] = ('site down', int(time.time()) + (5 * 60)) - sickgear.save_config() + self.save_main_config() return None def is_valid_mod(self, url): @@ -2088,7 +2101,7 @@ class TorrentProvider(GenericProvider): if maxed_out(response) and hasattr(self, 'password'): self.password = None - sickgear.save_config() + self.save_main_config() msg = failed_msg(response) if msg: logger.error(msg % self.name) diff --git a/sickgear/providers/immortalseed.py b/sickgear/providers/immortalseed.py index 2dffe029..f0a0c3e8 100644 --- a/sickgear/providers/immortalseed.py +++ b/sickgear/providers/immortalseed.py @@ -56,7 +56,7 @@ class ImmortalSeedProvider(generic.TorrentProvider): if secret_key != self.api_key: self.api_key = secret_key - sickgear.save_config() + self.save_main_config() return True diff --git a/sickgear/providers/speedcd.py b/sickgear/providers/speedcd.py index f1a12083..000f2378 100644 --- a/sickgear/providers/speedcd.py +++ b/sickgear/providers/speedcd.py @@ -92,7 +92,7 @@ class SpeedCDProvider(generic.TorrentProvider): self.digest = None if self.session.cookies.get('inSpeed_speedian'): self.digest = 'inSpeed_speedian=%s' % self.session.cookies.get('inSpeed_speedian') - sickgear.save_config() + self.save_main_config() result = True logger.debug('Cookie details for %s updated.' % self.name) elif not self.failure_count: