From 9df3effce34c4547f6f7c365cb265f9ec595574e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Moreira?= Date: Thu, 30 Jan 2020 11:17:55 -0300 Subject: [PATCH] [improvement][aur] synchronizing the package databases once a day --- CHANGELOG.md | 4 ++ README.md | 4 +- bauh/gems/arch/config.py | 2 +- bauh/gems/arch/controller.py | 111 ++++++++++++++++++++++------- bauh/gems/arch/pacman.py | 7 +- bauh/gems/arch/resources/locale/ca | 6 +- bauh/gems/arch/resources/locale/de | 6 +- bauh/gems/arch/resources/locale/en | 6 +- bauh/gems/arch/resources/locale/es | 6 +- bauh/gems/arch/resources/locale/it | 6 +- bauh/gems/arch/resources/locale/pt | 6 +- 11 files changed, 129 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a431bd1..cf526e9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - AUR: - downgrading time reduced due to the fix described in ***Fixes*** - the custom **makepkg.conf** generated at **~/.config/bauh/arch** will enable **ccache** if available on the system + - package databases synchronization once a day ( or every device reboot ) before the first package installation / upgrade / downgrade. This behavior can be disabled on **~/.config/arch.yml** / or the new settings panel: + ``` + sync_databases: true # enabled by default + ``` - Configuration ( **~/.config/bauh/config.yml** ) - new property **hdpi** allowing to disable HDPI improvements ``` diff --git a/README.md b/README.md index d79cca40..c9bd1078 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,7 @@ db_updater: ``` optimize: true # if 'false': disables the auto-compilation improvements transitive_checking: true # if 'false': the dependency checking process will be faster, but the application will ask for a confirmation every time a not installed dependency is detected. +sync_databases: true # package databases synchronization once a day ( or every device reboot ) before the first package installation / upgrade / downgrade ``` - Required dependencies: - **pacman** @@ -242,7 +243,8 @@ ui: tray: # system tray settings default_icon: null # defines a path to a custom icon updates_icon: null # defines a path to a custom icon indicating updates - hdpi: true # enables HDPI rendering improvements. Use 'false' to disable them if you think the interface looks strange. + hdpi: true # enables HDPI rendering improvements. Use 'false' to disable them if you think the interface looks strange. + auto_scale: false # activates Qt auto screen scale factor (QT_AUTO_SCREEN_SCALE_FACTOR). It fixes scaling issues for some desktop environments ( like Gnome ) updates: check_interval: 30 # the updates checking interval in SECONDS diff --git a/bauh/gems/arch/config.py b/bauh/gems/arch/config.py index 0dd25b8d..c701ece8 100644 --- a/bauh/gems/arch/config.py +++ b/bauh/gems/arch/config.py @@ -3,5 +3,5 @@ from bauh.gems.arch import CONFIG_FILE def read_config(update_file: bool = False) -> dict: - template = {'optimize': True, 'transitive_checking': True} + template = {'optimize': True, 'transitive_checking': True, "sync_databases": True} return read(CONFIG_FILE, template, update_file=update_file) diff --git a/bauh/gems/arch/controller.py b/bauh/gems/arch/controller.py index 5fd8266b..bc9cc51f 100644 --- a/bauh/gems/arch/controller.py +++ b/bauh/gems/arch/controller.py @@ -5,6 +5,7 @@ import shutil import subprocess import time import traceback +from datetime import datetime from math import floor from pathlib import Path from threading import Thread @@ -193,6 +194,9 @@ class ArchManager(SoftwareManager): handler = ProcessHandler(watcher) app_build_dir = '{}/build_{}'.format(BUILD_DIR, int(time.time())) + + self._sync_databases(root_password=root_password, handler=handler) + watcher.change_progress(5) try: @@ -769,6 +773,52 @@ class ArchManager(SoftwareManager): return False + def _sync_databases(self, root_password: str, handler: ProcessHandler): + sync_path = '/tmp/bauh/arch/sync' + + if self.local_config['sync_databases']: + if os.path.exists(sync_path): + with open(sync_path) as f: + sync_file = f.read() + + try: + sync_time = datetime.fromtimestamp(int(sync_file)) + now = datetime.now() + + if (now - sync_time).days > 0: + self.logger.info("Package databases synchronization out of date") + else: + msg = "Package databases already synchronized" + self.logger.info(msg) + handler.watcher.print(msg) + return + except: + self.logger.warning("Could not convert the database synchronization time from '{}".format(sync_path)) + traceback.print_exc() + + handler.watcher.change_substatus(self.i18n['arch.sync_databases.substatus']) + synced, output = handler.handle_simple(pacman.sync_databases(root_password=root_password, + force=True)) + if synced: + try: + Path('/tmp/bauh/arch').mkdir(parents=True, exist_ok=True) + with open('/tmp/bauh/arch/sync', 'w+') as f: + f.write(str(int(time.time()))) + except: + traceback.print_exc() + else: + self.logger.warning("It was not possible to synchronized the package databases") + handler.watcher.change_substatus(self.i18n['arch.sync_databases.substatus.error']) + else: + msg = "Package databases synchronization disabled" + handler.watcher.print(msg) + self.logger.info(msg) + + def _optimize_makepkg(self, watcher: ProcessWatcher): + if self.local_config['optimize'] and not os.path.exists(CUSTOM_MAKEPKG_FILE): + watcher.change_substatus(self.i18n['arch.makepkg.optimizing']) + ArchCompilationOptimizer(self.context.logger).optimize() + def install(self, pkg: ArchPackage, root_password: str, watcher: ProcessWatcher, skip_optdeps: bool = False) -> bool: clean_config = False @@ -776,11 +826,12 @@ class ArchManager(SoftwareManager): self.local_config = read_config() clean_config = True - if self.local_config['optimize'] and not os.path.exists(CUSTOM_MAKEPKG_FILE): - watcher.change_substatus(self.i18n['arch.makepkg.optimizing']) - ArchCompilationOptimizer(self.context.logger).optimize() + handler = ProcessHandler(watcher) - res = self._install_from_aur(pkg.name, pkg.package_base, pkg.maintainer, root_password, ProcessHandler(watcher), dependency=False, skip_optdeps=skip_optdeps) + self._sync_databases(root_password=root_password, handler=handler) + self._optimize_makepkg(watcher=watcher) + + res = self._install_from_aur(pkg.name, pkg.package_base, pkg.maintainer, root_password, handler, dependency=False, skip_optdeps=skip_optdeps) if res: if os.path.exists(pkg.get_disk_data_path()): @@ -890,33 +941,40 @@ class ArchManager(SoftwareManager): def get_screenshots(self, pkg: SoftwarePackage) -> List[str]: pass + def _gen_bool_selector(self, id_: str, label_key: str, tooltip_key: str, value: bool, max_width: int) -> SingleSelectComponent: + opts = [InputOption(label=self.i18n['yes'].capitalize(), value=True), + InputOption(label=self.i18n['no'].capitalize(), value=False)] + + return SingleSelectComponent(label=self.i18n[label_key].capitalize(), + options=opts, + default_option=[o for o in opts if o.value == value][0], + max_per_line=len(opts), + type_=SelectViewType.RADIO, + tooltip=self.i18n[tooltip_key], + max_width=max_width, + id_=id_) + def get_settings(self, screen_width: int, screen_height: int) -> ViewComponent: config = read_config() max_width = floor(screen_width * 0.15) - optz_opts = [InputOption(label=self.i18n['yes'].capitalize(), value=True), - InputOption(label=self.i18n['no'].capitalize(), value=False)] - - trans_check_opts = [InputOption(label=self.i18n['yes'].capitalize(), value=True), - InputOption(label=self.i18n['no'].capitalize(), value=False)] - fields = [ - SingleSelectComponent(label=self.i18n['arch.config.optimize'].capitalize(), - options=optz_opts, - default_option=[o for o in optz_opts if o.value == config['optimize']][0], - max_per_line=len(optz_opts), - type_=SelectViewType.RADIO, - tooltip=self.i18n['arch.config.optimize.tip'], - max_width=max_width, - id_='opts'), - SingleSelectComponent(label=self.i18n['arch.config.trans_dep_check'].capitalize(), - options=trans_check_opts, - default_option=[o for o in trans_check_opts if o.value == config['transitive_checking']][0], - max_per_line=len(trans_check_opts), - type_=SelectViewType.RADIO, - max_width=max_width, - tooltip=self.i18n['arch.config.trans_dep_check.tip'], - id_='dep_check')] + self._gen_bool_selector(id_='opts', + label_key='arch.config.optimize', + tooltip_key='arch.config.optimize.tip', + value=config['optimize'], + max_width=max_width), + self._gen_bool_selector(id_='dep_check', + label_key='arch.config.trans_dep_check', + tooltip_key='arch.config.trans_dep_check.tip', + value=config['transitive_checking'], + max_width=max_width), + self._gen_bool_selector(id_='sync_dbs', + label_key='arch.config.sync_dbs', + tooltip_key='arch.config.sync_dbs.tip', + value=config['sync_databases'], + max_width=max_width) + ] return PanelComponent([FormComponent(fields, label=self.i18n['installation'].capitalize())]) @@ -926,6 +984,7 @@ class ArchManager(SoftwareManager): form_install = component.components[0] config['optimize'] = form_install.get_component('opts').get_selected() config['transitive_checking'] = form_install.get_component('dep_check').get_selected() + config['sync_databases'] = form_install.get_component('sync_dbs').get_selected() try: save_config(config, CONFIG_FILE) diff --git a/bauh/gems/arch/pacman.py b/bauh/gems/arch/pacman.py index f531a950..a99c7569 100644 --- a/bauh/gems/arch/pacman.py +++ b/bauh/gems/arch/pacman.py @@ -2,7 +2,7 @@ import re from threading import Thread from typing import List, Set, Tuple -from bauh.commons.system import run_cmd, new_subprocess, new_root_subprocess, SystemProcess +from bauh.commons.system import run_cmd, new_subprocess, new_root_subprocess, SystemProcess, SimpleProcess from bauh.gems.arch.exceptions import PackageNotFoundException RE_DEPS = re.compile(r'[\w\-_]+:[\s\w_\-\.]+\s+\[\w+\]') @@ -354,3 +354,8 @@ def read_dependencies(name: str) -> Set[str]: depends_on.update([d for d in line.split(' ') if d and d.lower() != 'none']) return depends_on + + +def sync_databases(root_password: str, force: bool = False) -> SimpleProcess: + return SimpleProcess(cmd=['pacman', '-Sy{}'.format('y' if force else '')], + root_password=root_password) diff --git a/bauh/gems/arch/resources/locale/ca b/bauh/gems/arch/resources/locale/ca index fcb04317..a5fa5957 100644 --- a/bauh/gems/arch/resources/locale/ca +++ b/bauh/gems/arch/resources/locale/ca @@ -105,4 +105,8 @@ arch.makepkg.optimizing=Optimitzant la recopilació arch.config.optimize=optimize arch.config.trans_dep_check=check dependencies arch.config.optimize.tip=Optimized settings will be used in order to make the packages installation faster, otherwise the system settings will be used -arch.config.trans_dep_check.tip=If all the package dependencies should be verified before the installation starts. Otherwise they will be discovered during the installation \ No newline at end of file +arch.config.trans_dep_check.tip=If all the package dependencies should be verified before the installation starts. Otherwise they will be discovered during the installation +arch.sync_databases.substatus=Synchronizing package databases +arch.sync_databases.substatus.error=It was not possible to synchronize the package database +arch.config.sync_dbs=Synchronize packages databases +arch.config.sync_dbs.tip=Synchronizes the package databases once a day ( or after a device reboot ) before the first package installation, upgrade or downgrade. This option help to prevent errors during these operations. \ No newline at end of file diff --git a/bauh/gems/arch/resources/locale/de b/bauh/gems/arch/resources/locale/de index 42b4d9c0..be24bbe9 100644 --- a/bauh/gems/arch/resources/locale/de +++ b/bauh/gems/arch/resources/locale/de @@ -105,4 +105,8 @@ arch.makepkg.optimizing=Optimiert die Zusammenstellung arch.config.optimize=optimize arch.config.trans_dep_check=check dependencies arch.config.optimize.tip=Optimized settings will be used in order to make the packages installation faster, otherwise the system settings will be used -arch.config.trans_dep_check.tip=If all the package dependencies should be verified before the installation starts. Otherwise they will be discovered during the installation \ No newline at end of file +arch.config.trans_dep_check.tip=If all the package dependencies should be verified before the installation starts. Otherwise they will be discovered during the installation +arch.sync_databases.substatus=Synchronizing package databases +arch.sync_databases.substatus.error=It was not possible to synchronize the package database +arch.config.sync_dbs=Synchronize packages databases +arch.config.sync_dbs.tip=Synchronizes the package databases once a day ( or after a device reboot ) before the first package installation, upgrade or downgrade. This option help to prevent errors during these operations. \ No newline at end of file diff --git a/bauh/gems/arch/resources/locale/en b/bauh/gems/arch/resources/locale/en index 5d0c44cc..3364dbd5 100644 --- a/bauh/gems/arch/resources/locale/en +++ b/bauh/gems/arch/resources/locale/en @@ -105,4 +105,8 @@ arch.makepkg.optimizing=Optimizing the compilation arch.config.optimize=optimize arch.config.trans_dep_check=check dependencies arch.config.optimize.tip=Optimized settings will be used in order to make the packages installation faster, otherwise the system settings will be used -arch.config.trans_dep_check.tip=If all the package dependencies should be verified before the installation starts. Otherwise they will be discovered during the installation \ No newline at end of file +arch.config.trans_dep_check.tip=If all the package dependencies should be verified before the installation starts. Otherwise they will be discovered during the installation +arch.sync_databases.substatus=Synchronizing package databases +arch.sync_databases.substatus.error=It was not possible to synchronize the package database +arch.config.sync_dbs=Synchronize packages databases +arch.config.sync_dbs.tip=Synchronizes the package databases once a day ( or after a device reboot ) before the first package installation, upgrade or downgrade. This option help to prevent errors during these operations. \ No newline at end of file diff --git a/bauh/gems/arch/resources/locale/es b/bauh/gems/arch/resources/locale/es index 3a3ebbc7..1724f835 100644 --- a/bauh/gems/arch/resources/locale/es +++ b/bauh/gems/arch/resources/locale/es @@ -105,4 +105,8 @@ arch.makepkg.optimizing=Optimizando la compilación arch.config.optimize=optimizar arch.config.trans_dep_check=verificar dependencias arch.config.optimize.tip=Se usará una configuración optimizada para acelerar la instalación de los paquetes, de lo contrario se usará la configuración del sistema -arch.config.trans_dep_check.tip=Si todas las dependencias del paquete deben ser verificadas antes de que comience la instalación. De lo contrario, se descubrirán durante la instalación. \ No newline at end of file +arch.config.trans_dep_check.tip=Si todas las dependencias del paquete deben ser verificadas antes de que comience la instalación. De lo contrario, se descubrirán durante la instalación. +arch.sync_databases.substatus=Sincronizando bases de paquetes +arch.sync_databases.substatus.error=No fue posible sincronizar la base de paquetes +arch.config.sync_dbs=Sincronizar las bases de paquetes +arch.config.sync_dbs.tip=Sincroniza las bases de paquetes una vez al día ( o cada reinicialización del dispositivo ) antes de la primera instalación, actualización o reversión de un paquete. Esta opción ayuda a prevenir errores durante estas operaciones. \ No newline at end of file diff --git a/bauh/gems/arch/resources/locale/it b/bauh/gems/arch/resources/locale/it index 64c798ec..d2ec2cf0 100644 --- a/bauh/gems/arch/resources/locale/it +++ b/bauh/gems/arch/resources/locale/it @@ -73,4 +73,8 @@ arch.makepkg.optimizing=Ottimizzando la compilazione arch.config.optimize=optimize arch.config.trans_dep_check=check dependencies arch.config.optimize.tip=Optimized settings will be used in order to make the packages installation faster, otherwise the system settings will be used -arch.config.trans_dep_check.tip=If all the package dependencies should be verified before the installation starts. Otherwise they will be discovered during the installation \ No newline at end of file +arch.config.trans_dep_check.tip=If all the package dependencies should be verified before the installation starts. Otherwise they will be discovered during the installation +arch.sync_databases.substatus=Synchronizing package databases +arch.sync_databases.substatus.error=It was not possible to synchronize the package database +arch.config.sync_dbs=Synchronize packages databases +arch.config.sync_dbs.tip=Synchronizes the package databases once a day ( or after a device reboot ) before the first package installation, upgrade or downgrade. This option help to prevent errors during these operations. \ No newline at end of file diff --git a/bauh/gems/arch/resources/locale/pt b/bauh/gems/arch/resources/locale/pt index 621705d2..56db3c6e 100644 --- a/bauh/gems/arch/resources/locale/pt +++ b/bauh/gems/arch/resources/locale/pt @@ -105,4 +105,8 @@ arch.makepkg.optimizing=Otimizando a compilação arch.config.optimize=otimizar arch.config.trans_dep_check=verificar dependências arch.config.optimize.tip=Utilizará configurações otimizadas para que a instalação de pacotes seja mais rápida, caso contrário utilizará a do sistema -arch.config.trans_dep_check.tip=Se todas as dependências do pacote devem ser verificadas antes da instalação começar, caso contrário elas serão descobertas durante a instalação \ No newline at end of file +arch.config.trans_dep_check.tip=Se todas as dependências do pacote devem ser verificadas antes da instalação começar, caso contrário elas serão descobertas durante a instalação +arch.sync_databases.substatus=Sincronizando bases de pacotes +arch.sync_databases.substatus.error=Não foi possível sincronizar as bases de pacotes +arch.config.sync_dbs=Sincronizar bases de pacotes +arch.config.sync_dbs.tip=Sincroniza as bases de pacotes uma vez ao dia ( ou a cada reinicialização do dispositivo ) antes da primeira instalação, atualização ou reversão de um pacote. Essa opção ajuda a evitar erros durante essa operações. \ No newline at end of file