mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-09 02:54:16 +02:00
improvement -> all suported types now display a 'Checking configuration file' task during the initialization process
This commit is contained in:
@@ -1,80 +1,73 @@
|
||||
from pathlib import Path
|
||||
|
||||
import yaml
|
||||
|
||||
from bauh import __app_name__
|
||||
from bauh.commons.config import read_config as read
|
||||
from bauh.commons.config import YAMLConfigManager
|
||||
|
||||
CONFIG_PATH = '{}/.config/{}'.format(Path.home(), __app_name__)
|
||||
FILE_PATH = '{}/config.yml'.format(CONFIG_PATH)
|
||||
FILE_PATH = '{}/.config/{}/config.yml'.format(str(Path.home()), __app_name__)
|
||||
|
||||
|
||||
def read_config(update_file: bool = False) -> dict:
|
||||
default = {
|
||||
'gems': None,
|
||||
'memory_cache': {
|
||||
'data_expiration': 60 * 60,
|
||||
'icon_expiration': 60 * 5
|
||||
},
|
||||
'locale': None,
|
||||
'updates': {
|
||||
'check_interval': 30,
|
||||
'ask_for_reboot': True
|
||||
},
|
||||
'system': {
|
||||
'notifications': True,
|
||||
'single_dependency_checking': False
|
||||
},
|
||||
'suggestions': {
|
||||
'enabled': True,
|
||||
'by_type': 10
|
||||
},
|
||||
'ui': {
|
||||
'table': {
|
||||
'max_displayed': 50
|
||||
class CoreConfigManager(YAMLConfigManager):
|
||||
|
||||
def __init__(self):
|
||||
super(CoreConfigManager, self).__init__(config_file_path=FILE_PATH)
|
||||
|
||||
def get_default_config(self) -> dict:
|
||||
return {
|
||||
'gems': None,
|
||||
'memory_cache': {
|
||||
'data_expiration': 60 * 60,
|
||||
'icon_expiration': 60 * 5
|
||||
},
|
||||
'tray': {
|
||||
'default_icon': None,
|
||||
'updates_icon': None
|
||||
'locale': None,
|
||||
'updates': {
|
||||
'check_interval': 30,
|
||||
'ask_for_reboot': True
|
||||
},
|
||||
'qt_style': 'fusion',
|
||||
'hdpi': True,
|
||||
"auto_scale": False,
|
||||
"scale_factor": 1.0,
|
||||
'theme': 'light',
|
||||
'system_theme': False
|
||||
'system': {
|
||||
'notifications': True,
|
||||
'single_dependency_checking': False
|
||||
},
|
||||
'suggestions': {
|
||||
'enabled': True,
|
||||
'by_type': 10
|
||||
},
|
||||
'ui': {
|
||||
'table': {
|
||||
'max_displayed': 50
|
||||
},
|
||||
'tray': {
|
||||
'default_icon': None,
|
||||
'updates_icon': None
|
||||
},
|
||||
'qt_style': 'fusion',
|
||||
'hdpi': True,
|
||||
"auto_scale": False,
|
||||
"scale_factor": 1.0,
|
||||
'theme': 'light',
|
||||
'system_theme': False
|
||||
|
||||
},
|
||||
'download': {
|
||||
'multithreaded': True,
|
||||
'multithreaded_client': None,
|
||||
'icons': True
|
||||
},
|
||||
'store_root_password': True,
|
||||
'disk': {
|
||||
'trim': {
|
||||
'after_upgrade': False
|
||||
},
|
||||
'download': {
|
||||
'multithreaded': True,
|
||||
'multithreaded_client': None,
|
||||
'icons': True
|
||||
},
|
||||
'store_root_password': True,
|
||||
'disk': {
|
||||
'trim': {
|
||||
'after_upgrade': False
|
||||
}
|
||||
},
|
||||
'backup': {
|
||||
'enabled': True,
|
||||
'install': None,
|
||||
'uninstall': None,
|
||||
'downgrade': None,
|
||||
'upgrade': None,
|
||||
'mode': 'incremental',
|
||||
'type': 'rsync'
|
||||
},
|
||||
'boot': {
|
||||
'load_apps': True
|
||||
}
|
||||
},
|
||||
'backup': {
|
||||
'enabled': True,
|
||||
'install': None,
|
||||
'uninstall': None,
|
||||
'downgrade': None,
|
||||
'upgrade': None,
|
||||
'mode': 'incremental',
|
||||
'type': 'rsync'
|
||||
},
|
||||
'boot': {
|
||||
'load_apps': True
|
||||
}
|
||||
|
||||
}
|
||||
return read(FILE_PATH, default, update_file=update_file, update_async=True)
|
||||
|
||||
|
||||
def save(config: dict):
|
||||
Path(CONFIG_PATH).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
with open(FILE_PATH, 'w+') as f:
|
||||
f.write(yaml.safe_dump(config))
|
||||
|
||||
@@ -14,12 +14,14 @@ from bauh.api.abstract.model import SoftwarePackage, PackageUpdate, PackageHisto
|
||||
CustomSoftwareAction
|
||||
from bauh.api.abstract.view import ViewComponent, TabGroupComponent, MessageType
|
||||
from bauh.api.exception import NoInternetException
|
||||
from bauh.commons.boot import CreateConfigFile
|
||||
from bauh.commons.html import bold
|
||||
from bauh.commons.system import run_cmd
|
||||
from bauh.view.core.config import read_config
|
||||
from bauh.view.core.config import CoreConfigManager
|
||||
from bauh.view.core.settings import GenericSettingsManager
|
||||
from bauh.view.core.update import check_for_update
|
||||
from bauh.view.util import resource
|
||||
from bauh.view.util.resource import get_path
|
||||
from bauh.view.util.util import clean_app_files, restart_app
|
||||
|
||||
RE_IS_URL = re.compile(r'^https?://.+')
|
||||
@@ -52,6 +54,7 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
self.config = config
|
||||
self.settings_manager = settings_manager
|
||||
self.http_client = context.http_client
|
||||
self.configman = CoreConfigManager()
|
||||
self.extra_actions = [CustomSoftwareAction(i18n_label_key='action.reset',
|
||||
i18n_status_key='action.reset.status',
|
||||
manager_method='reset',
|
||||
@@ -402,14 +405,25 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
def prepare(self, task_manager: TaskManager, root_password: str, internet_available: bool):
|
||||
ti = time.time()
|
||||
self.logger.info("Initializing")
|
||||
taskman = task_manager if task_manager else TaskManager() # empty task manager to prevent null pointers
|
||||
|
||||
create_config = CreateConfigFile(taskman=taskman, configman=self.configman, i18n=self.i18n,
|
||||
task_icon_path=get_path('img/logo.svg'), logger=self.logger)
|
||||
create_config.start()
|
||||
|
||||
if self.managers:
|
||||
internet_on = self.context.is_internet_available()
|
||||
taskman = task_manager if task_manager else TaskManager() # empty task manager to prevent null pointers
|
||||
prepare_tasks = []
|
||||
for man in self.managers:
|
||||
if man not in self._already_prepared and self._can_work(man):
|
||||
man.prepare(taskman, root_password, internet_on)
|
||||
t = Thread(target=man.prepare, args=(taskman, root_password, internet_on), daemon=True)
|
||||
t.start()
|
||||
prepare_tasks.append(t)
|
||||
self._already_prepared.append(man)
|
||||
|
||||
for t in prepare_tasks:
|
||||
t.join()
|
||||
|
||||
tf = time.time()
|
||||
self.logger.info("Finished. Took {0:.2f} seconds".format(tf - ti))
|
||||
|
||||
@@ -525,7 +539,8 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
working_managers=self.working_managers,
|
||||
logger=self.logger,
|
||||
i18n=self.i18n,
|
||||
file_downloader=self.context.file_downloader)
|
||||
file_downloader=self.context.file_downloader,
|
||||
configman=self.configman)
|
||||
else:
|
||||
self.settings_manager.managers = self.managers
|
||||
self.settings_manager.working_managers = self.working_managers
|
||||
@@ -618,7 +633,7 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
if man_actions:
|
||||
actions.extend(man_actions)
|
||||
|
||||
app_config = read_config()
|
||||
app_config = self.configman.get_config()
|
||||
|
||||
for action, available in self.dynamic_extra_actions.items():
|
||||
if available(app_config):
|
||||
|
||||
@@ -13,8 +13,8 @@ from bauh.api.abstract.view import ViewComponent, TabComponent, InputOption, Tex
|
||||
PanelComponent, FormComponent, TabGroupComponent, SingleSelectComponent, SelectViewType, TextInputComponent, \
|
||||
FileChooserComponent, RangeInputComponent
|
||||
from bauh.commons.view_utils import new_select
|
||||
from bauh.view.core import config, timeshift
|
||||
from bauh.view.core.config import read_config
|
||||
from bauh.view.core import timeshift
|
||||
from bauh.view.core.config import CoreConfigManager
|
||||
from bauh.view.core.downloader import AdaptableFileDownloader
|
||||
from bauh.view.util import translation
|
||||
from bauh.view.util.translation import I18n
|
||||
@@ -23,12 +23,13 @@ from bauh.view.util.translation import I18n
|
||||
class GenericSettingsManager:
|
||||
|
||||
def __init__(self, managers: List[SoftwareManager], working_managers: List[SoftwareManager],
|
||||
logger: logging.Logger, i18n: I18n, file_downloader: FileDownloader):
|
||||
logger: logging.Logger, i18n: I18n, file_downloader: FileDownloader, configman: CoreConfigManager):
|
||||
self.i18n = i18n
|
||||
self.managers = managers
|
||||
self.working_managers = working_managers
|
||||
self.logger = logger
|
||||
self.file_downloader = file_downloader
|
||||
self.configman = configman
|
||||
|
||||
def get_settings(self, screen_width: int, screen_height: int) -> ViewComponent:
|
||||
tabs = list()
|
||||
@@ -54,7 +55,7 @@ class GenericSettingsManager:
|
||||
if man.is_enabled() and man in self.working_managers:
|
||||
def_gem_opts.add(opt)
|
||||
|
||||
core_config = read_config()
|
||||
core_config = self.configman.get_config()
|
||||
|
||||
if gem_opts:
|
||||
type_help = TextComponent(html=self.i18n['core.config.types.tip'])
|
||||
@@ -340,7 +341,7 @@ class GenericSettingsManager:
|
||||
ui: PanelComponent,
|
||||
tray: PanelComponent,
|
||||
gems_panel: PanelComponent) -> Tuple[bool, Optional[List[str]]]:
|
||||
core_config = config.read_config()
|
||||
core_config = self.configman.get_config()
|
||||
|
||||
# general
|
||||
general_form = general.components[0]
|
||||
@@ -443,7 +444,7 @@ class GenericSettingsManager:
|
||||
core_config['gems'] = None if core_config['gems'] is None and len(checked_gems) == len(self.managers) else checked_gems
|
||||
|
||||
try:
|
||||
config.save(core_config)
|
||||
self.configman.save_config(core_config)
|
||||
return True, None
|
||||
except:
|
||||
return False, [traceback.format_exc()]
|
||||
|
||||
Reference in New Issue
Block a user