diff --git a/bauh/commons/util.py b/bauh/commons/util.py new file mode 100644 index 00000000..31f644b0 --- /dev/null +++ b/bauh/commons/util.py @@ -0,0 +1,11 @@ +import collections + + +def deep_update(source: dict, overrides: dict): + for key, value in overrides.items(): + if isinstance(value, collections.Mapping) and value: + returned = deep_update(source.get(key, {}), value) + source[key] = returned + else: + source[key] = overrides[key] + return source diff --git a/bauh/gems/web/config.py b/bauh/gems/web/config.py index 7f154282..e278ba1c 100644 --- a/bauh/gems/web/config.py +++ b/bauh/gems/web/config.py @@ -4,19 +4,31 @@ from pathlib import Path import yaml from bauh.api.constants import CONFIG_PATH +from bauh.commons import util from bauh.gems.web import CONFIG_FILE -def read_config() -> dict: +def read_config(update_file: bool = False) -> dict: + default_config = { + 'environment': { + 'system': False, + 'electron': {'version': None} + } + } if not os.path.exists(CONFIG_FILE): - config = {'environment': {'system': False}} - Path(CONFIG_PATH).mkdir(parents=True, exist_ok=True) with open(CONFIG_FILE, 'w+') as f: - f.write(yaml.dump(config)) + f.write(yaml.dump(default_config)) + else: with open(CONFIG_FILE) as f: - config = yaml.safe_load(f.read()) + local_config = yaml.safe_load(f.read()) - return config + util.deep_update(default_config, local_config) + + if update_file: + with open(CONFIG_FILE, 'w+') as f: + f.write(yaml.dump(default_config)) + + return default_config diff --git a/bauh/gems/web/controller.py b/bauh/gems/web/controller.py index be39ec7d..4cfc496d 100644 --- a/bauh/gems/web/controller.py +++ b/bauh/gems/web/controller.py @@ -574,7 +574,7 @@ class WebApplicationManager(SoftwareManager): def can_work(self) -> bool: if BS4_AVAILABLE and LXML_AVAILABLE: - config = read_config() + config = read_config(update_file=True) use_system_env = config['environment']['system'] if not use_system_env: diff --git a/bauh/gems/web/environment.py b/bauh/gems/web/environment.py index 93bcb34a..e041aa03 100644 --- a/bauh/gems/web/environment.py +++ b/bauh/gems/web/environment.py @@ -236,7 +236,14 @@ class EnvironmentUpdater: self.logger.warning('Could not install / update nativefier') return - res = self.install_electron(version=settings['electron']['version'], is_x86_x64_arch=is_x86_x64_arch, + electron_version = current_config['environment']['electron']['version'] + + if electron_version: + self.logger.warning("Using custom Electron version {}".format(electron_version)) + else: + electron_version = settings['electron']['version'] + + res = self.install_electron(version=electron_version, is_x86_x64_arch=is_x86_x64_arch, watcher=handler.watcher if handler else None) if res: