Skip to content

Commit

Permalink
Fix recreating config file from cache
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleGoogle committed Oct 20, 2019
1 parent 3dd4e96 commit b92adac
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
10 changes: 3 additions & 7 deletions src/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@
# ===

[library]
sources = [
'drm-free',
'trove',
'keys',
]
sources = [ 'drm-free', 'trove', 'keys',]
show_revealed_keys = false

[installed]
search_dirs = [
]
# provide installed games location(s):
search_dirs = [ ]
21 changes: 7 additions & 14 deletions src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from dataclasses import dataclass, field
from typing import Any, Dict, Callable, Mapping, Tuple, Optional, Set

from version import __version__
from consts import SOURCE, HP, CURRENT_SYSTEM


Expand Down Expand Up @@ -73,7 +72,7 @@ class Settings:
LOCAL_CONFIG_FILE = pathlib.Path(__file__).parent / 'config.ini'

def __init__(self, cache: Dict[str, str], save_cache_callback: Callable):
self._curr_ver = __version__
self._curr_ver = '1'
self._prev_ver = cache.get('version')
self._cache = cache
self._push_cache = save_cache_callback
Expand Down Expand Up @@ -122,8 +121,7 @@ def _load_config_file(self, config_path: pathlib.Path) -> Mapping[str, Any]:
return {}

def _update_user_config(self):
"""Simple migrations"""
logging.info(f'Recreating user config file with new entries')
logging.info(f'Recreating user config from cache')
data = toml.dumps(self._config)
with open(self.LOCAL_CONFIG_FILE, 'r') as f:
comment = ''
Expand Down Expand Up @@ -160,16 +158,11 @@ def reload_local_config_if_changed(self, first_run=False) -> bool:
logging.debug(f'local config: {local_config}')

if first_run:
if self._prev_ver is None or self._curr_ver <= self._prev_ver:
self._config = {**self._cached_config, **local_config}
else: # prioritize cached config in case of plugin update
self._config = {**local_config, **self._cached_config}
logging.debug(f'updated config: {self._config}')
if self._config.keys() - local_config.keys():
logging.debug(f'Config shape differs!')
self._update_user_config()
if self._prev_ver != self._curr_ver:
self._cache['version'] = self._curr_ver
# config migrations here
self._config = {**local_config, **self._cached_config}
if local_config != self._cached_config:
self._update_user_config()
self._cache['version'] = self._curr_ver
else:
self._config.update(local_config)

Expand Down
2 changes: 2 additions & 0 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ def copy(c, output=DIST_PLUGIN, galaxy_path=GALAXY_PATH):
print('copying source code ...')
for file_ in glob("src/*.py"):
shutil.copy(file_, output)
for file_ in glob("src/*.ini"):
shutil.copy(file_, output)


@task
Expand Down

0 comments on commit b92adac

Please sign in to comment.