improvement -> all suported types now display a 'Checking configuration file' task during the initialization process

This commit is contained in:
Vinicius Moreira
2020-12-30 13:35:15 -03:00
parent 01bd532465
commit c91e982243
69 changed files with 1059 additions and 561 deletions

View File

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

View File

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

View File

@@ -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()]

View File

@@ -1,6 +1,8 @@
import datetime
import operator
import time
from functools import reduce
from threading import Lock
from typing import Tuple, Optional
from PyQt5.QtCore import QSize, Qt, QThread, pyqtSignal, QCoreApplication
@@ -34,7 +36,10 @@ class Prepare(QThread, TaskManager):
self.context = context
self.waiting_password = False
self.password_response = None
self._registered = 0
self._tasks_added = set()
self._tasks_finished = set()
self._add_lock = Lock()
self._finish_lock = Lock()
def ask_password(self) -> Tuple[bool, Optional[str]]:
self.waiting_password = True
@@ -58,20 +63,42 @@ class Prepare(QThread, TaskManager):
QCoreApplication.exit(1)
self.manager.prepare(self, root_pwd, None)
self.signal_started.emit(self._registered)
self._add_lock.acquire()
self.signal_started.emit(len(self._tasks_added))
self._add_lock.release()
def update_progress(self, task_id: str, progress: float, substatus: str):
self.signal_update.emit(task_id, progress, substatus)
if task_id in self._tasks_added:
self.signal_update.emit(task_id, progress, substatus)
def update_output(self, task_id: str, output: str):
self.signal_output.emit(task_id, output)
if task_id in self._tasks_added:
self.signal_output.emit(task_id, output)
def register_task(self, id_: str, label: str, icon_path: str):
self._registered += 1
self.signal_register.emit(id_, label, icon_path)
self._add_lock.acquire()
if id_ not in self._tasks_added:
self._tasks_added.add(id_)
self.signal_register.emit(id_, label, icon_path)
self._add_lock.release()
def finish_task(self, task_id: str):
self.signal_finished.emit(task_id)
self._add_lock.acquire()
task_registered = task_id in self._tasks_added
self._add_lock.release()
if not task_registered:
return
self._finish_lock.acquire()
if task_id not in self._tasks_finished:
self._tasks_finished.add(task_id)
self.signal_finished.emit(task_id)
self._finish_lock.release()
class CheckFinished(QThread):
@@ -84,7 +111,7 @@ class CheckFinished(QThread):
def run(self):
while True:
if self.total == self.finished:
if self.finished == self.total:
break
self.msleep(5)
@@ -134,6 +161,7 @@ class PreparePanel(QWidget, TaskManager):
self.output = {}
self.added_tasks = 0
self.ftasks = 0
self.started_at = None
self.self_close = False
self.prepare_thread = Prepare(self.context, manager, self.i18n)
@@ -263,6 +291,7 @@ class PreparePanel(QWidget, TaskManager):
centralize(self)
def start(self, tasks: int):
self.started_at = time.time()
self.check_thread.total = tasks
self.check_thread.start()
self.skip_thread.start()
@@ -387,9 +416,8 @@ class PreparePanel(QWidget, TaskManager):
def finish_task(self, task_id: str):
task = self.tasks[task_id]
task['lb_sub'].setText('')
for key in ('lb_prog', 'lb_status'):
for key in ('lb_prog', 'lb_status', 'lb_sub'):
label = task[key]
label.setProperty('status', 'done')
label.style().unpolish(label)
@@ -402,10 +430,9 @@ class PreparePanel(QWidget, TaskManager):
self.ftasks += 1
self.signal_status.emit(self.ftasks)
if self.table.rowCount() == self.ftasks:
self.label_top.setText(self.i18n['ready'].capitalize())
def finish(self):
now = time.time()
self.context.logger.info("{0} tasks finished in {1:.9f} seconds".format(self.ftasks, (now - self.started_at)))
if self.isVisible():
self.manage_window.show()

View File

@@ -9,7 +9,7 @@ from PyQt5.QtWidgets import QLineEdit, QApplication, QDialog, QPushButton, QVBox
from bauh.api.abstract.context import ApplicationContext
from bauh.commons.system import new_subprocess
from bauh.view.core.config import read_config
from bauh.view.core.config import CoreConfigManager
from bauh.view.qt.components import QtComponentsManager, new_spacer
from bauh.view.util import util
from bauh.view.util.translation import I18n
@@ -131,7 +131,7 @@ class RootDialog(QDialog):
def ask_password(context: ApplicationContext, i18n: I18n, app_config: Optional[dict] = None,
comp_manager: Optional[QtComponentsManager] = None, tries: int = 3) -> Tuple[bool, Optional[str]]:
current_config = read_config() if not app_config else app_config
current_config = CoreConfigManager().get_config() if not app_config else app_config
store_password = bool(current_config['store_root_password'])

View File

@@ -23,8 +23,8 @@ from bauh.api.exception import NoInternetException
from bauh.commons import user
from bauh.commons.html import bold
from bauh.commons.system import get_human_size_str, ProcessHandler, SimpleProcess
from bauh.view.core import timeshift, config
from bauh.view.core.config import read_config
from bauh.view.core import timeshift
from bauh.view.core.config import CoreConfigManager
from bauh.view.qt import commons
from bauh.view.qt.view_model import PackageView, PackageViewStatus
from bauh.view.util.translation import I18n
@@ -466,7 +466,7 @@ class UpgradeSelected(AsyncAction):
self.change_substatus('')
app_config = read_config()
app_config = CoreConfigManager().get_config()
# backup dialog ( if enabled, supported and accepted )
should_backup = bkp_supported
@@ -572,7 +572,7 @@ class UninstallPackage(AsyncAction):
pkg=self.pkg,
i18n=self.i18n,
root_password=self.root_pwd,
app_config=read_config())
app_config=CoreConfigManager().get_config())
if not proceed:
self.notify_finished({'success': False, 'removed': None, 'pkg': self.pkg})
self.pkg = None
@@ -615,7 +615,7 @@ class DowngradePackage(AsyncAction):
pkg=self.pkg,
i18n=self.i18n,
root_password=self.root_pwd,
app_config=read_config())
app_config=CoreConfigManager().get_config())
if not proceed:
self.notify_finished({'app': self.pkg, 'success': success})
@@ -707,7 +707,7 @@ class InstallPackage(AsyncAction):
pkg=self.pkg,
i18n=self.i18n,
root_password=self.root_pwd,
app_config=read_config())
app_config=CoreConfigManager().get_config())
if not proceed:
self.signal_finished.emit(res)
@@ -1007,7 +1007,7 @@ class CustomAction(AsyncAction):
res = {'success': False, 'pkg': self.pkg, 'action': self.custom_action, 'error': None, 'error_type': MessageType.ERROR}
if self.custom_action.backup:
proceed, _ = self.request_backup(app_config=read_config(),
proceed, _ = self.request_backup(app_config=CoreConfigManager.get_config(),
action_key=None,
i18n=self.i18n,
root_password=self.root_pwd,
@@ -1081,10 +1081,11 @@ class SaveTheme(QThread):
def run(self):
if self.theme_key:
core_config = read_config()
configman = CoreConfigManager()
core_config = configman.get_config()
core_config['ui']['theme'] = self.theme_key
try:
config.save(core_config)
configman.save_config(core_config)
except:
traceback.print_exc()

View File

@@ -22,7 +22,7 @@ from bauh.commons import user
from bauh.commons.html import bold
from bauh.context import set_theme
from bauh.stylesheet import read_all_themes_metadata, ThemeMetadata
from bauh.view.core.config import read_config
from bauh.view.core.config import CoreConfigManager
from bauh.view.core.tray_client import notify_tray
from bauh.view.qt import dialog, commons, qt_utils
from bauh.view.qt.about import AboutDialog
@@ -1586,7 +1586,7 @@ class ManageWindow(QWidget):
menu_row.exec_()
def _map_theme_actions(self, menu: QMenu) -> List[QCustomMenuAction]:
core_config = read_config()
core_config = CoreConfigManager().get_config()
current_theme_key, current_action = core_config['ui']['theme'], None

View File

@@ -391,6 +391,8 @@ status.caching_data=Sestan emmagatzemant {} dades a la memòria cau al disc
style=estil
success=success
summary=resum
task.checking_config=Checking configuration file
task.checking_config.saving=Creating file
task.download_categories=Download de categories
task.waiting_task=Waiting for {}
type=tipus

View File

@@ -391,6 +391,8 @@ status.caching_data={} Daten auf der Festplatte zwischenspeichern
style=Stil
success=success
summary=Zusammenfassung
task.checking_config=Checking configuration file
task.checking_config.saving=Creating file
task.download_categories=Downloading categories
task.waiting_task=Waiting for {}
type=Typ

View File

@@ -392,6 +392,8 @@ status.caching_data=Caching {} data to disk
style=style
success=success
summary=summary
task.checking_config=Checking configuration file
task.checking_config.saving=Creating file
task.download_categories=Downloading categories
task.waiting_task=Waiting for {}
type=type

View File

@@ -394,6 +394,8 @@ status.caching_data=Almacenando en antememoria los datos de {} para el disco
style=estilo
success=éxito
summary=resumen
task.checking_config=Verificando archivo de configuración
task.checking_config.saving=Creando archivo
task.download_categories=Descargando categorías
task.waiting_task=Esperando por {}
type=tipo

View File

@@ -388,6 +388,8 @@ status.caching_data=Mise en cache des données de {} sur disque
style=style
success=succès
summary=résumé
task.checking_config=Checking configuration file
task.checking_config.saving=Creating file
task.download_categories=Téléchargement des catégories
task.waiting_task=Waiting for {}
type=type

View File

@@ -394,6 +394,8 @@ status.caching_data=Memorizza {} dati sul disco
style=stile
success=success
summary=riepilogo
task.checking_config=Checking configuration file
task.checking_config.saving=Creating file
task.download_categories=Download delle categorie
task.waiting_task=Waiting for {}
type=tipe

View File

@@ -392,6 +392,8 @@ status.caching_data=Cacheando dados de {} para o disco
style=estilo
success=sucesso
summary=resumo
task.checking_config=Verificando arquivo de configuração
task.checking_config.saving=Criando arquivo
task.download_categories=Baixando categorias
task.waiting_task=Aguardando {}
type=tipo

View File

@@ -391,6 +391,8 @@ status.caching_data=Кэширование данных {} на диск
style=Стиль
success=success
summary=Суммарно
task.checking_config=Checking configuration file
task.checking_config.saving=Creating file
task.download_categories=Downloading categories
task.waiting_task=Waiting for {}
type=Тип

View File

@@ -391,6 +391,8 @@ status.caching_data={} verilerini diske önbellekle
style=Görünüm biçimi
success=başarılı
summary=özet
task.checking_config=Checking configuration file
task.checking_config.saving=Creating file
task.download_categories=Kategoriler indiriliyor
task.waiting_task=Waiting for {}
type=tür

View File

@@ -238,7 +238,7 @@ PreparePanel QTableWidget#tasks {
background-color: @inner_widget.background.color;
}
PreparePanel QLabel#task_status[status = "done"], QLabel#task_progress[status = "done"] {
PreparePanel QLabel#task_status[status = "done"], PreparePanel QLabel#task_progress[status = "done"], PreparePanel QLabel#task_substatus[status = "done"] {
color: @task.done.color;
}

View File

@@ -219,7 +219,7 @@ PreparePanel QPushButton#bt_hide_details {
background: none;
}
PreparePanel QLabel#task_status[status = "done"], QLabel#task_progress[status = "done"] {
PreparePanel QLabel#task_status[status = "done"], PreparePanel QLabel#task_progress[status = "done"], PreparePanel QLabel#task_substatus[status = "done"] {
text-decoration: line-through;
}

View File

@@ -145,11 +145,11 @@ PreparePanel QTableWidget#tasks {
background-color: @task.background.color;
}
PreparePanel QLabel#task_status[status = "running"], QLabel#task_progress[status = "running"] {
PreparePanel QLabel#task_status[status = "running"], PreparePanel QLabel#task_progress[status = "running"] {
font-weight: 525;
}
PreparePanel QLabel#task_status[status = "done"], QLabel#task_progress[status = "done"] {
PreparePanel QLabel#task_status[status = "done"], PreparePanel QLabel#task_progress[status = "done"], PreparePanel QLabel#task_substatus[status = "done"] {
color: @task.done.color;
}

View File

@@ -195,7 +195,7 @@ PreparePanel QLabel#task_status[status = "running"], QLabel#task_progress[status
color: @task.running.color;
}
PreparePanel QLabel#task_status[status = "done"], QLabel#task_progress[status = "done"] {
PreparePanel QLabel#task_status[status = "done"], PreparePanel QLabel#task_progress[status = "done"], PreparePanel QLabel#task_substatus[status = "done"]{
color: @task.done.color;
}