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
This commit is contained in:
Prinz23 2024-08-12 21:33:28 +01:00 committed by JackDandy
parent e67f74a262
commit 69eea899ef
5 changed files with 39 additions and 9 deletions

View file

@ -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 * Fix saving config.ini after restart and startup

View file

@ -76,6 +76,7 @@ CFG = None # type: ConfigObj
CONFIG_FILE = '' CONFIG_FILE = ''
CONFIG_VERSION = None CONFIG_VERSION = None
CONFIG_OLD = None CONFIG_OLD = None
CONFIG_LOADED = False
# Default encryption version (0 for None) # Default encryption version (0 for None)
ENCRYPTION_VERSION = 0 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, \ 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, \ CREATE_MISSING_SHOW_DIRS, SHOW_DIRS_WITH_DOTS, \
RECENTSEARCH_STARTUP, NAMING_FORCE_FOLDERS, SOCKET_TIMEOUT, DEBUG, TVINFO_DEFAULT, \ 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 REMOVE_FILENAME_CHARS, IMPORT_DEFAULT_CHECKED_SHOWS, WANTEDLIST_CACHE, MODULE_UPDATE_STRING, EXT_UPDATES
# Add Show Search # Add Show Search
global RESULTS_SORTBY 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() \ header = callable(getattr(cur_provider, '_init_api', False)) and False is cur_provider._init_api() \
and header or {} and header or {}
cur_provider.headers.update(header) cur_provider.headers.update(header)
update_config |= cur_provider.should_save_config()
# current commit hash # current commit hash
CUR_COMMIT_HASH = check_setting_str(CFG, 'General', 'cur_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 # Get expected config version
CONFIG_VERSION = max(ConfigMigrator(CFG).migration_names) CONFIG_VERSION = max(ConfigMigrator(CFG).migration_names)
# we have fully loaded all config settings into vars
CONFIG_LOADED = True
if update_config: if update_config:
_save_config(force=True) _save_config(force=True)
@ -1896,7 +1902,9 @@ def save_config(force=False):
:param force: force save config even if unchanged :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 # use queue if it's available, otherwise, call save_config directly
hasattr(config_events, 'put') and config_events.put(force) or _save_config(force) 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): def _save_config(force=False, **kwargs):
# type: (bool, ...) -> None # type: (bool, ...) -> None
global CONFIG_OLD global CONFIG_OLD, CONFIG_LOADED
if not CONFIG_LOADED:
return
new_config = ConfigObj() new_config = ConfigObj()
new_config.filename = CONFIG_FILE new_config.filename = CONFIG_FILE

View file

@ -275,6 +275,19 @@ class GenericProvider(object):
self.scene_rej_nuked = False # type: bool self.scene_rej_nuked = False # type: bool
self.scene_nuked_active = 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): def _load_fail_values(self):
if hasattr(sickgear, 'DATA_DIR'): if hasattr(sickgear, 'DATA_DIR'):
my_db = db.DBConnection('cache.db') 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()))): 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.PROVIDER_HOMES[self.get_id()] = (cur_url, int(time.time()) + (60*60))
sickgear.save_config() self.save_main_config()
return cur_url return cur_url
seen_attr = 'PROVIDER_SEEN' seen_attr = 'PROVIDER_SEEN'
@ -1975,7 +1988,7 @@ class TorrentProvider(GenericProvider):
if not hasattr(self, 'url_api'): if not hasattr(self, 'url_api'):
self.urls = {} self.urls = {}
sickgear.PROVIDER_HOMES[self.get_id()] = ('site down', int(time.time()) + (5 * 60)) sickgear.PROVIDER_HOMES[self.get_id()] = ('site down', int(time.time()) + (5 * 60))
sickgear.save_config() self.save_main_config()
return None return None
def is_valid_mod(self, url): def is_valid_mod(self, url):
@ -2088,7 +2101,7 @@ class TorrentProvider(GenericProvider):
if maxed_out(response) and hasattr(self, 'password'): if maxed_out(response) and hasattr(self, 'password'):
self.password = None self.password = None
sickgear.save_config() self.save_main_config()
msg = failed_msg(response) msg = failed_msg(response)
if msg: if msg:
logger.error(msg % self.name) logger.error(msg % self.name)

View file

@ -56,7 +56,7 @@ class ImmortalSeedProvider(generic.TorrentProvider):
if secret_key != self.api_key: if secret_key != self.api_key:
self.api_key = secret_key self.api_key = secret_key
sickgear.save_config() self.save_main_config()
return True return True

View file

@ -92,7 +92,7 @@ class SpeedCDProvider(generic.TorrentProvider):
self.digest = None self.digest = None
if self.session.cookies.get('inSpeed_speedian'): if self.session.cookies.get('inSpeed_speedian'):
self.digest = 'inSpeed_speedian=%s' % 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 result = True
logger.debug('Cookie details for %s updated.' % self.name) logger.debug('Cookie details for %s updated.' % self.name)
elif not self.failure_count: elif not self.failure_count: