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

@@ -14,14 +14,14 @@ from bauh.api.abstract.view import SingleSelectComponent, SelectViewType, InputO
FormComponent, TextInputComponent
from bauh.api.exception import NoInternetException
from bauh.commons import resource
from bauh.commons.boot import CreateConfigFile
from bauh.commons.category import CategoriesDownloader
from bauh.commons.config import save_config
from bauh.commons.html import bold
from bauh.commons.system import SystemProcess, ProcessHandler, new_root_subprocess, get_human_size_str
from bauh.commons.view_utils import new_select
from bauh.gems.snap import snap, URL_CATEGORIES_FILE, CATEGORIES_FILE_PATH, SUGGESTIONS_FILE, \
get_icon_path, snapd, CONFIG_FILE, ROOT_DIR
from bauh.gems.snap.config import read_config
get_icon_path, snapd, ROOT_DIR
from bauh.gems.snap.config import SnapConfigManager
from bauh.gems.snap.model import SnapApplication
from bauh.gems.snap.snapd import SnapdClient
@@ -42,6 +42,7 @@ class SnapManager(SoftwareManager):
self.categories = {}
self.suggestions_cache = context.cache_factory.new()
self.info_path = None
self.configman = SnapConfigManager()
self.custom_actions = [
CustomSoftwareAction(i18n_status_key='snap.action.refresh.status',
i18n_label_key='snap.action.refresh.label',
@@ -187,7 +188,7 @@ class SnapManager(SoftwareManager):
installed_names = {s['name'] for s in SnapdClient(self.logger).list_all_snaps()}
client = SnapdClient(self.logger)
snap_config = read_config()
snap_config = self.configman.get_config()
try:
channel = self._request_channel_installation(pkg=pkg, snap_config=snap_config, snapd_client=client, watcher=watcher)
@@ -283,27 +284,35 @@ class SnapManager(SoftwareManager):
except:
return False
def _start_category_task(self, task_man: TaskManager):
if task_man:
task_man.register_task('snap_cats', self.i18n['task.download_categories'], get_icon_path())
task_man.update_progress('snap_cats', 50, None)
def _start_category_task(self, taskman: TaskManager, create_config: CreateConfigFile, downloader: CategoriesDownloader):
if taskman:
taskman.update_progress('snap_cats', 0, self.i18n['task.waiting_task'].format(bold(create_config.task_name)))
create_config.join()
def _finish_category_task(self, task_man: TaskManager):
if task_man:
task_man.update_progress('snap_cats', 100, None)
task_man.finish_task('snap_cats')
categories_exp = create_config.config['categories_exp']
downloader.expiration = categories_exp if isinstance(categories_exp, int) else None
taskman.update_progress('snap_cats', 1, None)
def _finish_category_task(self, taskman: TaskManager):
if taskman:
taskman.update_progress('snap_cats', 100, None)
taskman.finish_task('snap_cats')
def prepare(self, task_manager: TaskManager, root_password: str, internet_available: bool):
snap_config = read_config()
create_config = CreateConfigFile(taskman=task_manager, configman=self.configman, i18n=self.i18n,
task_icon_path=get_icon_path(), logger=self.logger)
create_config.start()
CategoriesDownloader(id_='snap', manager=self, http_client=self.http_client, logger=self.logger,
url_categories_file=URL_CATEGORIES_FILE,
categories_path=CATEGORIES_FILE_PATH,
expiration=snap_config['categories_exp'] if isinstance(snap_config['categories_exp'], int) else 0,
internet_connection=internet_available,
internet_checker=self.context.internet_checker,
before=lambda: self._start_category_task(task_manager),
after=lambda: self._finish_category_task(task_manager)).start()
task_manager.register_task('snap_cats', self.i18n['task.download_categories'], get_icon_path())
category_downloader = CategoriesDownloader(id_='snap', manager=self, http_client=self.http_client,
logger=self.logger,
url_categories_file=URL_CATEGORIES_FILE,
categories_path=CATEGORIES_FILE_PATH,
internet_connection=internet_available,
internet_checker=self.context.internet_checker,
after=lambda: self._finish_category_task(task_manager))
category_downloader.before = lambda: self._start_category_task(task_manager, create_config, category_downloader)
category_downloader.start()
def list_updates(self, internet_available: bool) -> List[PackageUpdate]:
pass
@@ -436,7 +445,7 @@ class SnapManager(SoftwareManager):
return pkg.screenshots if pkg.has_screenshots() else []
def get_settings(self, screen_width: int, screen_height: int) -> ViewComponent:
snap_config = read_config()
snap_config = self.configman.get_config()
max_width = 200
install_channel = new_select(label=self.i18n['snap.config.install_channel'],
@@ -457,14 +466,14 @@ class SnapManager(SoftwareManager):
return PanelComponent([FormComponent([install_channel, categories_exp], self.i18n['installation'].capitalize())])
def save_settings(self, component: ViewComponent) -> Tuple[bool, Optional[List[str]]]:
config = read_config()
snap_config = self.configman.get_config()
panel = component.components[0]
config['install_channel'] = panel.get_component('snap_install_channel').get_selected()
config['categories_exp'] = panel.get_component('snap_cat_exp').get_int_value()
snap_config['install_channel'] = panel.get_component('snap_install_channel').get_selected()
snap_config['categories_exp'] = panel.get_component('snap_cat_exp').get_int_value()
try:
save_config(config, CONFIG_FILE)
self.configman.save_config(snap_config)
return True, None
except:
return False, [traceback.format_exc()]