diff --git a/README.md b/README.md index c4bfd21e..0292f77f 100644 --- a/README.md +++ b/README.md @@ -134,13 +134,13 @@ will be pre-downloaded faster ( it does **NOT** modify your **pacman** settings #### Web Applications ( web ) - It allows the installation of native Web applications by typing an address / URL in the search bar. -- It also offers the possibility to customize the app to be generated the way you want: [TODO image or video] +- It also offers the possibility to customize the generated app the way you want: [TODO image or video] - It also provides some suggestions coming with predefined settings, and they also can be retrieved by searching their names. They are defined at [suggestions.yml](https://github.com/vinifmor/bauh-files/blob/master/web/suggestions.yml), and downloaded during the application usage. - It relies on [NodeJS](https://nodejs.org/en/), [Electron](https://electronjs.org/) and [nativefier](https://github.com/jiahaog/nativefier) to do all the magic, but you do not need them installed on your system. An isolated installation environment will be generated at **~/.local/share/bauh/web/env**. -- The isolated environment is generated based on the settings defined in [environment.yml](https://github.com/vinifmor/bauh-files/blob/master/web/environment.yml) - that is downloaded during runtime. +- The isolated environment is created based on the settings defined in [environment.yml](https://github.com/vinifmor/bauh-files/blob/master/web/environment.yml) + ( downloaded during runtime ). - Some applications require Javascript fixes to properly work. If it is a known fix, bauh will download the file JS file from [fix](https://github.com/vinifmor/bauh-files/tree/master/web/fix) and install it with the generated app. - The installed applications are located at **~/.local/share/bauh/installed**. @@ -148,12 +148,12 @@ install it with the generated app. - When the Tray Mode **Start Minimized** is defined during the installation setup, a desktop entry will be also generated at **~/.config/autostart** allowing the application to launch automatically attached to system tray after the boot. - The configuration file for the Web apps support is located at **~/.config/bauh/web.yml** and it allows the following customizations: -` +``` environment: electron: version: null # set a custom Electron version here ( e.g: '6.1.4' ) system: false # set it to 'true' if you want to use the nativefier version globally installed on your system -` +``` - Required packages: Arch systems ( **python-lxml**, **python-beautifulsoup4** ), Debian systems ( you will need to install the following packages with pip: **beautifulsoup4**, **lxml** ) ### General settings diff --git a/bauh/commons/config.py b/bauh/commons/config.py new file mode 100644 index 00000000..87890cb2 --- /dev/null +++ b/bauh/commons/config.py @@ -0,0 +1,27 @@ +import os +from pathlib import Path + +import yaml + +from bauh.commons import util + + +def read_config(file_path: str, template: dict, update_file: bool = False) -> dict: + if not os.path.exists(file_path): + Path(file_path).mkdir(parents=True, exist_ok=True) + + with open(file_path, 'w+') as f: + f.write(yaml.dump(template)) + + else: + with open(file_path) as f: + local_config = yaml.safe_load(f.read()) + + if local_config: + util.deep_update(template, local_config) + + if update_file: + with open(file_path, 'w+') as f: + f.write(yaml.dump(template)) + + return template diff --git a/bauh/gems/web/config.py b/bauh/gems/web/config.py index e278ba1c..b532704a 100644 --- a/bauh/gems/web/config.py +++ b/bauh/gems/web/config.py @@ -1,10 +1,4 @@ -import os -from pathlib import Path - -import yaml - -from bauh.api.constants import CONFIG_PATH -from bauh.commons import util +from bauh.commons.config import read_config as read from bauh.gems.web import CONFIG_FILE @@ -15,20 +9,6 @@ def read_config(update_file: bool = False) -> dict: 'electron': {'version': None} } } - if not os.path.exists(CONFIG_FILE): - Path(CONFIG_PATH).mkdir(parents=True, exist_ok=True) - with open(CONFIG_FILE, 'w+') as f: - f.write(yaml.dump(default_config)) + return read(CONFIG_FILE, default_config, update_file) - else: - with open(CONFIG_FILE) as f: - local_config = yaml.safe_load(f.read()) - - 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