[wgem] config: allowing to use a custom electron version

This commit is contained in:
Vinícius Moreira
2019-12-17 15:54:01 -03:00
parent e87c95ea9e
commit 70bd76c52a
4 changed files with 38 additions and 8 deletions

11
bauh/commons/util.py Normal file
View File

@@ -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

View File

@@ -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

View File

@@ -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:

View File

@@ -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: