From af6367b0abe3bab2da301391f4d374d0ddd80a8b Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Tue, 12 Jan 2021 16:06:34 -0300 Subject: [PATCH] [arch] fixes -> not displaying installed AUR packages when AUR support is disabled | downloading AUR index during the initialization process when AUR support is disabled --- CHANGELOG.md | 2 + bauh/api/abstract/view.py | 46 +++++++++++++++------ bauh/gems/arch/controller.py | 79 ++++++++++++++++++++---------------- bauh/gems/arch/worker.py | 5 ++- 4 files changed, 83 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf1b9f40..a6b70f99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - crashing when information of a given package is not available - displaying "provided" repository packages on the search results (e.g: **nvidia** would appear as a package) - calling pacman to read installed packages when "Repositories" and "AUR" properties are set to "false" (it would not display the packages, but the call was unnecessary being done) + - not displaying installed AUR packages when AUR support is disabled + - downloading AUR index during the initialization process when AUR support is disabled - UI - displaying a popup when information of a given package is not available diff --git a/bauh/api/abstract/view.py b/bauh/api/abstract/view.py index 30743b38..4050fe90 100644 --- a/bauh/api/abstract/view.py +++ b/bauh/api/abstract/view.py @@ -33,18 +33,6 @@ class SpacerComponent(ViewComponent): super(SpacerComponent, self).__init__(id_=None) -class PanelComponent(ViewComponent): - - def __init__(self, components: List[ViewComponent], id_: str = None): - super(PanelComponent, self).__init__(id_=id_) - self.components = components - self.component_map = {c.id: c for c in components if c.id is not None} if components else None - - def get_component(self, id_: str) -> ViewComponent: - if self.component_map: - return self.component_map.get(id_) - - class InputViewComponent(ViewComponent): """ Represents an component which needs a user interaction to provide its value @@ -96,6 +84,7 @@ class SingleSelectComponent(InputViewComponent): self.label = label self.options = options self.value = default_option + self.init_value = default_option self.max_per_line = max_per_line self.tooltip = tooltip self.max_width = max_width @@ -105,6 +94,9 @@ class SingleSelectComponent(InputViewComponent): if self.value: return self.value.value + def changed(self) -> bool: + return self.init_value != self.value + class MultipleSelectComponent(InputViewComponent): @@ -214,10 +206,18 @@ class FormComponent(ViewComponent): self.components = components self.component_map = {c.id: c for c in components if c.id} if components else None - def get_component(self, id_: str) -> ViewComponent: + def get_component(self, id_: str) -> Optional[ViewComponent]: if self.component_map: return self.component_map.get(id_) + def get_single_select_component(self, id_: str) -> Optional[SingleSelectComponent]: + comp = self.get_component(id_) + + if comp: + if not isinstance(comp, SingleSelectComponent): + raise Exception("'{}' is not a {}".format(id_, SingleSelectComponent.__class__.__name__)) + return comp + class FileChooserComponent(ViewComponent): @@ -281,3 +281,23 @@ class RangeInputComponent(InputViewComponent): self.step = step_value self.value = value self.max_width = max_width + + +class PanelComponent(ViewComponent): + + def __init__(self, components: List[ViewComponent], id_: str = None): + super(PanelComponent, self).__init__(id_=id_) + self.components = components + self.component_map = {c.id: c for c in components if c.id is not None} if components else None + + def get_component(self, id_: str) -> Optional[ViewComponent]: + if self.component_map: + return self.component_map.get(id_) + + def get_form_component(self, id_: str) -> Optional[FormComponent]: + comp = self.get_component(id_) + + if comp: + if not isinstance(comp, FormComponent): + raise Exception("'{}' is not a {}".format(id_, FormComponent.__class__.__name__)) + return comp diff --git a/bauh/gems/arch/controller.py b/bauh/gems/arch/controller.py index 4101ccdc..7c9c9737 100644 --- a/bauh/gems/arch/controller.py +++ b/bauh/gems/arch/controller.py @@ -515,11 +515,8 @@ class ArchManager(SoftwareManager): thread_updates.start() repo_map = pacman.map_repositories(repo_pkgs) - if len(repo_map) != len(repo_pkgs): - self.logger.warning("Not mapped all signed packages repositories. Mapped: {}. Total: {}".format(len(repo_map), len(repo_pkgs))) thread_updates.join() - self.logger.info("Repository updates found" if updates else "No repository updates found") for name, data in repo_pkgs.items(): @@ -545,6 +542,9 @@ class ArchManager(SoftwareManager): if disk_loader: disk_loader.fill(pkg, sync=True) + if not aur_supported and pkg.repository == 'aur': + pkg.repository = None # if AUR support is disabled, the repository should be reported as "unknown" + if aur_supported or pkg.repository != 'aur': # this case happens when a package was removed from AUR pkgs.append(pkg) @@ -567,24 +567,27 @@ class ArchManager(SoftwareManager): aur_pkgs, repo_pkgs = None, None - if repos_supported and installed['signed']: + if repos_supported: repo_pkgs = installed['signed'] if installed['not_signed']: - if self.index_aur: - self.index_aur.join() + if aur_supported: + if self.index_aur: + self.index_aur.join() - aur_index = self.aur_client.read_index() + aur_index = self.aur_client.read_index() - for pkg in {*installed['not_signed']}: - if pkg not in aur_index: - if repo_pkgs is not None: - repo_pkgs[pkg] = installed['not_signed'][pkg] + for pkg in {*installed['not_signed']}: + if pkg not in aur_index: + if repos_supported: + repo_pkgs[pkg] = installed['not_signed'][pkg] - if aur_supported and installed['not_signed']: - del installed['not_signed'][pkg] + if aur_supported and installed['not_signed']: + del installed['not_signed'][pkg] - aur_pkgs = installed['not_signed'] if aur_supported else None + aur_pkgs = installed['not_signed'] + elif repos_supported: + repo_pkgs.update(installed['not_signed']) pkgs = [] if repo_pkgs or aur_pkgs: @@ -2896,35 +2899,41 @@ class ArchManager(SoftwareManager): value=arch_config['categories_exp'] if isinstance(arch_config['categories_exp'], int) else ''), ] - return PanelComponent([FormComponent(fields, spaces=False)]) + return PanelComponent([FormComponent(fields, spaces=False, id_='root')]) def save_settings(self, component: PanelComponent) -> Tuple[bool, Optional[List[str]]]: arch_config = self.configman.get_config() - panel = component.components[0] - arch_config['repositories'] = panel.get_component('repos').get_selected() - arch_config['aur'] = panel.get_component('aur').get_selected() - arch_config['optimize'] = panel.get_component('opts').get_selected() - arch_config['sync_databases'] = panel.get_component('sync_dbs').get_selected() - arch_config['sync_databases_startup'] = panel.get_component('sync_dbs_start').get_selected() - arch_config['clean_cached'] = panel.get_component('clean_cached').get_selected() - arch_config['refresh_mirrors_startup'] = panel.get_component('ref_mirs').get_selected() - arch_config['mirrors_sort_limit'] = panel.get_component('mirrors_sort_limit').get_int_value() - arch_config['repositories_mthread_download'] = panel.get_component('mthread_download').get_selected() - arch_config['automatch_providers'] = panel.get_component('autoprovs').get_selected() - arch_config['edit_aur_pkgbuild'] = panel.get_component('edit_aur_pkgbuild').get_selected() - arch_config['aur_remove_build_dir'] = panel.get_component('aur_remove_build_dir').get_selected() - arch_config['aur_build_dir'] = panel.get_component('aur_build_dir').file_path - arch_config['aur_build_only_chosen'] = panel.get_component('aur_build_only_chosen').get_selected() - arch_config['aur_idx_exp'] = panel.get_component('aur_idx_exp').get_int_value() - arch_config['check_dependency_breakage'] = panel.get_component('check_dependency_breakage').get_selected() - arch_config['suggest_optdep_uninstall'] = panel.get_component('suggest_optdep_uninstall').get_selected() - arch_config['suggest_unneeded_uninstall'] = panel.get_component('suggest_unneeded_uninstall').get_selected() - arch_config['categories_exp'] = panel.get_component('arch_cats_exp').get_int_value() + form = component.get_form_component('root') + arch_config['repositories'] = form.get_single_select_component('repos').get_selected() + arch_config['optimize'] = form.get_single_select_component('opts').get_selected() + arch_config['sync_databases'] = form.get_single_select_component('sync_dbs').get_selected() + arch_config['sync_databases_startup'] = form.get_single_select_component('sync_dbs_start').get_selected() + arch_config['clean_cached'] = form.get_single_select_component('clean_cached').get_selected() + arch_config['refresh_mirrors_startup'] = form.get_single_select_component('ref_mirs').get_selected() + arch_config['mirrors_sort_limit'] = form.get_component('mirrors_sort_limit').get_int_value() + arch_config['repositories_mthread_download'] = form.get_component('mthread_download').get_selected() + arch_config['automatch_providers'] = form.get_single_select_component('autoprovs').get_selected() + arch_config['edit_aur_pkgbuild'] = form.get_single_select_component('edit_aur_pkgbuild').get_selected() + arch_config['aur_remove_build_dir'] = form.get_single_select_component('aur_remove_build_dir').get_selected() + arch_config['aur_build_dir'] = form.get_component('aur_build_dir').file_path + arch_config['aur_build_only_chosen'] = form.get_single_select_component('aur_build_only_chosen').get_selected() + arch_config['aur_idx_exp'] = form.get_component('aur_idx_exp').get_int_value() + arch_config['check_dependency_breakage'] = form.get_single_select_component('check_dependency_breakage').get_selected() + arch_config['suggest_optdep_uninstall'] = form.get_single_select_component('suggest_optdep_uninstall').get_selected() + arch_config['suggest_unneeded_uninstall'] = form.get_single_select_component('suggest_unneeded_uninstall').get_selected() + arch_config['categories_exp'] = form.get_component('arch_cats_exp').get_int_value() if not arch_config['aur_build_dir']: arch_config['aur_build_dir'] = None + aur_enabled_select = form.get_single_select_component('aur') + arch_config['aur'] = aur_enabled_select.get_selected() + + if aur_enabled_select.changed() and arch_config['aur']: + self.index_aur = AURIndexUpdater(context=self.context, taskman=TaskManager(), arch_config=arch_config) + self.index_aur.start() + try: self.configman.save_config(arch_config) return True, None diff --git a/bauh/gems/arch/worker.py b/bauh/gems/arch/worker.py index c055aa0b..e91e5c16 100644 --- a/bauh/gems/arch/worker.py +++ b/bauh/gems/arch/worker.py @@ -44,6 +44,9 @@ class AURIndexUpdater(Thread): self.taskman.register_task(self.task_id, self.i18n['arch.task.aur.index.status'], get_icon_path()) def should_update(self) -> bool: + if not aur.is_supported(self.config): + return False + try: exp_hours = int(self.config['aur_idx_exp']) except: @@ -134,7 +137,7 @@ class AURIndexUpdater(Thread): tf = time.time() self.taskman.finish_task(self.task_id) - self.logger.info("Finished. Took {0:.2f} seconds".format(tf - ti)) + self.logger.info("Finished. Took {0:.5f} seconds".format(tf - ti)) class ArchDiskCacheUpdater(Thread):