mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 02:24:16 +02:00
[improvement][aur] synchronizing the package databases once a day
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
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.
|
||||
@@ -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
|
||||
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.
|
||||
@@ -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
|
||||
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.
|
||||
@@ -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.
|
||||
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.
|
||||
@@ -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
|
||||
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.
|
||||
@@ -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
|
||||
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.
|
||||
Reference in New Issue
Block a user