mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 03:34:15 +02:00
[wgem] config: allowing to use a custom electron version
This commit is contained in:
11
bauh/commons/util.py
Normal file
11
bauh/commons/util.py
Normal 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
|
||||||
@@ -4,19 +4,31 @@ from pathlib import Path
|
|||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from bauh.api.constants import CONFIG_PATH
|
from bauh.api.constants import CONFIG_PATH
|
||||||
|
from bauh.commons import util
|
||||||
from bauh.gems.web import CONFIG_FILE
|
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):
|
if not os.path.exists(CONFIG_FILE):
|
||||||
config = {'environment': {'system': False}}
|
|
||||||
|
|
||||||
Path(CONFIG_PATH).mkdir(parents=True, exist_ok=True)
|
Path(CONFIG_PATH).mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
with open(CONFIG_FILE, 'w+') as f:
|
with open(CONFIG_FILE, 'w+') as f:
|
||||||
f.write(yaml.dump(config))
|
f.write(yaml.dump(default_config))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
with open(CONFIG_FILE) as f:
|
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
|
||||||
|
|||||||
@@ -574,7 +574,7 @@ class WebApplicationManager(SoftwareManager):
|
|||||||
|
|
||||||
def can_work(self) -> bool:
|
def can_work(self) -> bool:
|
||||||
if BS4_AVAILABLE and LXML_AVAILABLE:
|
if BS4_AVAILABLE and LXML_AVAILABLE:
|
||||||
config = read_config()
|
config = read_config(update_file=True)
|
||||||
use_system_env = config['environment']['system']
|
use_system_env = config['environment']['system']
|
||||||
|
|
||||||
if not use_system_env:
|
if not use_system_env:
|
||||||
|
|||||||
@@ -236,7 +236,14 @@ class EnvironmentUpdater:
|
|||||||
self.logger.warning('Could not install / update nativefier')
|
self.logger.warning('Could not install / update nativefier')
|
||||||
return
|
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)
|
watcher=handler.watcher if handler else None)
|
||||||
|
|
||||||
if res:
|
if res:
|
||||||
|
|||||||
Reference in New Issue
Block a user