[arch] feature -> AUR: rebuild-detector integration

This commit is contained in:
Vinicius Moreira
2021-01-14 11:29:17 -03:00
parent f25f5daaad
commit 0680a3118d
18 changed files with 169 additions and 49 deletions

View File

@@ -1,6 +1,6 @@
from abc import ABC, abstractmethod
from enum import Enum
from typing import List
from typing import List, Optional
from bauh.api.constants import CACHE_PATH
@@ -223,6 +223,12 @@ class SoftwarePackage(ABC):
"""
return self.name
def get_update_tip(self) -> Optional[str]:
"""
custom 'version' update tooltip
"""
return
@abstractmethod
def supports_backup(self) -> bool:
pass

View File

@@ -25,7 +25,7 @@ USE_GLOBAL_INTERPRETER = bool(os.getenv('VIRTUAL_ENV'))
SIZE_MULTIPLIERS = ((0.001, 'Kb'), (0.000001, 'Mb'), (0.000000001, 'Gb'), (0.000000000001, 'Tb'))
def gen_env(global_interpreter: bool, lang: str = DEFAULT_LANG, extra_paths: Set[str] = None) -> dict:
def gen_env(global_interpreter: bool, lang: str = DEFAULT_LANG, extra_paths: Optional[Set[str]] = None) -> dict:
custom_env = dict(os.environ)
if lang:
@@ -33,6 +33,7 @@ def gen_env(global_interpreter: bool, lang: str = DEFAULT_LANG, extra_paths: Set
if global_interpreter: # to avoid subprocess calls to the virtualenv python interpreter instead of the global one.
custom_env['PATH'] = GLOBAL_INTERPRETER_PATH
else:
custom_env['PATH'] = PATH
@@ -322,11 +323,19 @@ def check_enabled_services(*names: str) -> Dict[str, bool]:
return {s: status[i].strip().lower() == 'enabled' for i, s in enumerate(names) if s}
def execute(cmd: str, shell: bool = False, cwd: Optional[str] = None, output: bool = True) -> Tuple[int, Optional[str]]:
p = subprocess.run(args=cmd.split(' ') if not shell else [cmd],
stdout=subprocess.PIPE if output else subprocess.DEVNULL,
stderr=subprocess.STDOUT if output else subprocess.DEVNULL,
shell=shell,
cwd=cwd)
def execute(cmd: str, shell: bool = False, cwd: Optional[str] = None, output: bool = True, custom_env: Optional[dict] = None) -> Tuple[int, Optional[str]]:
params = {
'args': cmd.split(' ') if not shell else [cmd],
'stdout': subprocess.PIPE if output else subprocess.DEVNULL,
'stderr': subprocess.STDOUT if output else subprocess.DEVNULL,
'shell': shell
}
if cwd is not None:
params['cwd'] = cwd
if custom_env is not None:
params['env'] = custom_env
p = subprocess.run(**params)
return p.returncode, p.stdout.decode() if p.stdout else None

View File

@@ -38,4 +38,5 @@ class ArchConfigManager(YAMLConfigManager):
'suggest_unneeded_uninstall': False,
'suggest_optdep_uninstall': False,
'aur_idx_exp': 1,
'categories_exp': 24}
'categories_exp': 24,
'aur_rebuild_detector': True}

View File

@@ -37,7 +37,7 @@ from bauh.commons.view_utils import new_select
from bauh.gems.arch import aur, pacman, makepkg, message, confirmation, disk, git, \
gpg, URL_CATEGORIES_FILE, CATEGORIES_FILE_PATH, CUSTOM_MAKEPKG_FILE, SUGGESTIONS_FILE, \
get_icon_path, database, mirrors, sorting, cpu_manager, UPDATES_IGNORED_FILE, \
CONFIG_DIR, EDITABLE_PKGBUILDS_FILE, URL_GPG_SERVERS, BUILD_DIR
CONFIG_DIR, EDITABLE_PKGBUILDS_FILE, URL_GPG_SERVERS, BUILD_DIR, rebuild_detector
from bauh.gems.arch.aur import AURClient
from bauh.gems.arch.config import get_build_dir, ArchConfigManager
from bauh.gems.arch.dependencies import DependenciesAnalyser
@@ -449,48 +449,57 @@ class ArchManager(SoftwareManager):
return res
def _fill_aur_pkgs(self, aur_pkgs: dict, output: List[ArchPackage], disk_loader: DiskCacheLoader, internet_available: bool,
arch_config: dict):
arch_config: dict, rebuild_check: Optional[Thread], to_rebuild: Set[str]):
if internet_available:
try:
pkgsinfo = self.aur_client.get_info(aur_pkgs.keys())
if pkgsinfo:
editable_pkgbuilds = self._read_editable_pkgbuilds() if arch_config['edit_aur_pkgbuild'] is not False else None
for pkgdata in pkgsinfo:
pkg = self.aur_mapper.map_api_data(pkgdata, aur_pkgs, self.categories)
pkg.pkgbuild_editable = pkg.name in editable_pkgbuilds if editable_pkgbuilds is not None else None
if pkg.installed:
if disk_loader:
disk_loader.fill(pkg, sync=True)
pkg.update = self._check_aur_package_update(pkg=pkg,
installed_data=aur_pkgs.get(pkg.name, {}),
api_data=pkgdata)
pkg.status = PackageStatus.READY
output.append(pkg)
return
except requests.exceptions.ConnectionError:
self.logger.warning('Could not retrieve installed AUR packages API data. It seems the internet connection is off.')
self.logger.info("Reading only local AUR packages data")
return
editable_pkgbuilds = self._read_editable_pkgbuilds() if arch_config['edit_aur_pkgbuild'] is not False else None
for name, data in aur_pkgs.items():
pkg = ArchPackage(name=name, version=data.get('version'),
latest_version=data.get('version'), description=data.get('description'),
installed=True, repository='aur', i18n=self.i18n)
if pkgsinfo:
editable_pkgbuilds = self._read_editable_pkgbuilds() if arch_config['edit_aur_pkgbuild'] is not False else None
pkg.categories = self.categories.get(pkg.name)
pkg.pkgbuild_editable = pkg.name in editable_pkgbuilds if editable_pkgbuilds is not None else None
if rebuild_check:
self.logger.info("Waiting for rebuild-detector")
rebuild_check.join()
if disk_loader:
disk_loader.fill(pkg)
for pkgdata in pkgsinfo:
pkg = self.aur_mapper.map_api_data(pkgdata, aur_pkgs, self.categories)
pkg.pkgbuild_editable = pkg.name in editable_pkgbuilds if editable_pkgbuilds is not None else None
pkg.status = PackageStatus.READY
output.append(pkg)
if pkg.installed:
if disk_loader:
disk_loader.fill(pkg, sync=True)
pkg.update = self._check_aur_package_update(pkg=pkg,
installed_data=aur_pkgs.get(pkg.name, {}),
api_data=pkgdata)
if to_rebuild and not pkg.update and pkg.name in to_rebuild:
pkg.require_rebuild = True
pkg.update = True
pkg.status = PackageStatus.READY
output.append(pkg)
else:
editable_pkgbuilds = self._read_editable_pkgbuilds() if arch_config['edit_aur_pkgbuild'] is not False else None
for name, data in aur_pkgs.items():
pkg = ArchPackage(name=name, version=data.get('version'),
latest_version=data.get('version'), description=data.get('description'),
installed=True, repository='aur', i18n=self.i18n)
pkg.categories = self.categories.get(pkg.name)
pkg.pkgbuild_editable = pkg.name in editable_pkgbuilds if editable_pkgbuilds is not None else None
if disk_loader:
disk_loader.fill(pkg)
pkg.status = PackageStatus.READY
output.append(pkg)
def _check_aur_package_update(self, pkg: ArchPackage, installed_data: dict, api_data: dict) -> bool:
if pkg.last_modified is None: # if last_modified is not available, then the install_date will be used instead
@@ -555,6 +564,16 @@ class ArchManager(SoftwareManager):
self.disk_cache_updater.join()
self.logger.info("Disk cache ready")
def __fill_packages_to_rebuild(self, output: Set[str]):
if rebuild_detector.is_installed():
if 'PYCHARM_CLASSPATH' in os.environ:
self.logger.warning("'rebuild-detector' is currently not working within PyCharm. Aborting...")
return
self.logger.info("rebuild-detector: checking")
output.update(rebuild_detector.list_required_rebuild())
self.logger.info("rebuild-detector: packages detected -> {}".format(output))
def read_installed(self, disk_loader: Optional[DiskCacheLoader], limit: int = -1, only_apps: bool = False, pkg_types: Set[Type[SoftwarePackage]] = None, internet_available: bool = None, names: Iterable[str] = None, wait_disk_cache: bool = True) -> SearchResult:
self.aur_client.clean_caches()
arch_config = self.configman.get_config()
@@ -564,6 +583,11 @@ class ArchManager(SoftwareManager):
if not aur_supported and not repos_supported:
return SearchResult.empty()
to_rebuild, rebuild_check = set(), None
if aur_supported and arch_config['aur_rebuild_detector']:
rebuild_check = Thread(target=self.__fill_packages_to_rebuild, args=(to_rebuild,), daemon=True)
rebuild_check.start()
installed = pacman.map_installed(names=names)
aur_pkgs, repo_pkgs = None, None
@@ -598,7 +622,7 @@ class ArchManager(SoftwareManager):
map_threads = []
if aur_pkgs:
t = Thread(target=self._fill_aur_pkgs, args=(aur_pkgs, pkgs, disk_loader, internet_available, arch_config), daemon=True)
t = Thread(target=self._fill_aur_pkgs, args=(aur_pkgs, pkgs, disk_loader, internet_available, arch_config, rebuild_check, to_rebuild), daemon=True)
t.start()
map_threads.append(t)
@@ -2800,6 +2824,14 @@ class ArchManager(SoftwareManager):
label_params=['(AUR)'],
capitalize_label=False,
max_width=max_width),
self._gen_bool_selector(id_='rebuild_detector',
label_key='arch.config.aur_rebuild_detector',
tooltip_key='arch.config.aur_rebuild_detector.tip',
value=bool(arch_config['aur_rebuild_detector']),
label_params=['(AUR)'],
tooltip_params=["'rebuild-detector'"],
capitalize_label=False,
max_width=max_width),
self._gen_bool_selector(id_='autoprovs',
label_key='arch.config.automatch_providers',
tooltip_key='arch.config.automatch_providers.tip',
@@ -2908,6 +2940,7 @@ class ArchManager(SoftwareManager):
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['aur_rebuild_detector'] = form.get_single_select_component('rebuild_detector').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()

View File

@@ -37,7 +37,8 @@ class ArchPackage(SoftwarePackage):
maintainer: str = None, url_download: str = None, pkgbuild: str = None, repository: str = None,
desktop_entry: str = None, installed: bool = False, srcinfo: dict = None, dependencies: Set[str] = None,
categories: List[str] = None, i18n: I18n = None, update_ignored: bool = False, arch: str = None,
pkgbuild_editable: bool = None, install_date: Optional[int] = None, commit: Optional[str] = None):
pkgbuild_editable: bool = None, install_date: Optional[int] = None, commit: Optional[str] = None,
require_rebuild: bool = False):
super(ArchPackage, self).__init__(name=name, version=version, latest_version=latest_version, description=description,
installed=installed, categories=categories)
@@ -62,6 +63,7 @@ class ArchPackage(SoftwarePackage):
self.pkgbuild_editable = pkgbuild_editable # if the PKGBUILD can be edited by the user (only for AUR)
self.install_date = install_date
self.commit = commit # only for AUR for downgrading purposes
self.require_rebuild = require_rebuild
@staticmethod
def disk_cache_path(pkgname: str):
@@ -189,6 +191,10 @@ class ArchPackage(SoftwarePackage):
return actions
def get_update_tip(self) -> Optional[str]:
if self.repository == 'aur' and self.require_rebuild:
return self.i18n['arch.package.requires_rebuild'] + ' (rebuild)'
def __hash__(self):
if self.view_name is not None:
return hash((self.view_name, self.repository))

View File

@@ -0,0 +1,24 @@
from typing import Set
from bauh.commons import system
def is_installed() -> bool:
return system.execute(cmd='which checkrebuild', output=False)[0] == 0
def list_required_rebuild() -> Set[str]:
code, output = system.execute(cmd='checkrebuild')
required = set()
if code == 0 and output:
for line in output.split('\n'):
line_strip = line.strip()
if line_strip:
line_split = line_strip.split('\t')
if len(line_split) > 1:
required.add(line_split[1])
return required

View File

@@ -37,6 +37,8 @@ arch.checking.missing_deps=Verificació de les dependències que falten de {}
arch.clone=Sestà clonant el dipòsit {} de lAUR
arch.config.aur=AUR packages
arch.config.aur.tip=It allows to manage AUR packages. git must be installed.
arch.config.aur_rebuild_detector=Check reinstallation need {}
arch.config.aur_rebuild_detector.tip=It checks if packages built with old library versions require to be rebuilt. If a package needs to be rebuilt, it will be marked for update ({} must be installed)
arch.config.automatch_providers=Auto-define dependency providers
arch.config.automatch_providers.tip=It automatically chooses which provider will be used for a package dependency when both names are equal.
arch.config.aur_build_dir=Build directory (AUR)
@@ -204,6 +206,7 @@ arch.missing_deps_found=Dependències mancants per a {}
arch.mthread_downloaded.error.cache_dir=It was not possible to create the cache directory {}
arch.mthread_downloaded.error.cancelled=Operation cancelled
arch.optdeps.checking=Sestan comprovant les dependències opcionals de {}
arch.package.requires_rebuild=It needs to be reinstalled
arch.providers=providers
arch.substatus.conflicts=Checking for conflicts
arch.substatus.disk_space=Checking available disk space

View File

@@ -37,6 +37,8 @@ arch.checking.missing_deps=Überprüfen der fehlenden Abhängigkeiten von {}
arch.clone=AUR Repository {} wird kopiert
arch.config.aur=AUR packages
arch.config.aur.tip=It allows to manage AUR packages. git must be installed.
arch.config.aur_rebuild_detector=Check reinstallation need {}
arch.config.aur_rebuild_detector.tip=It checks if packages built with old library versions require to be rebuilt. If a package needs to be rebuilt, it will be marked for update ({} must be installed)
arch.config.automatch_providers=Auto-define dependency providers
arch.config.automatch_providers.tip=It automatically chooses which provider will be used for a package dependency when both names are equal.
arch.config.aur_build_dir=Build directory (AUR)
@@ -204,6 +206,7 @@ arch.missing_deps_found=Fehlende Abhängigkeiten für {}
arch.mthread_downloaded.error.cache_dir=It was not possible to create the cache directory {}
arch.mthread_downloaded.error.cancelled=Operation cancelled
arch.optdeps.checking={} optionale Abhängigkeiten überprüfen
arch.package.requires_rebuild=It needs to be reinstalled
arch.providers=providers
arch.substatus.conflicts=Checking for conflicts
arch.substatus.disk_space=Checking available disk space

View File

@@ -37,6 +37,8 @@ arch.checking.missing_deps=Verifying missing dependencies of {}
arch.clone=Cloning the AUR repository {}
arch.config.aur=AUR packages
arch.config.aur.tip=It allows to manage AUR packages. git must be installed.
arch.config.aur_rebuild_detector=Check reinstallation need {}
arch.config.aur_rebuild_detector.tip=It checks if packages built with old library versions require to be rebuilt. If a package needs to be rebuilt, it will be marked for update ({} must be installed)
arch.config.automatch_providers=Auto-define dependency providers
arch.config.automatch_providers.tip=It automatically chooses which provider will be used for a package dependency when both names are equal.
arch.config.aur_build_dir=Build directory (AUR)
@@ -204,6 +206,7 @@ arch.missing_deps_found=Missing dependencies for {}
arch.mthread_downloaded.error.cache_dir=It was not possible to create the cache directory {}
arch.mthread_downloaded.error.cancelled=Operation cancelled
arch.optdeps.checking=Checking {} optional dependencies
arch.package.requires_rebuild=It needs to be reinstalled
arch.providers=providers
arch.substatus.conflicts=Checking for conflicts
arch.substatus.disk_space=Checking available disk space

View File

@@ -37,6 +37,8 @@ arch.checking.missing_deps=Verificando las dependencias faltantes de {}
arch.clone=Clonando el repositorio {} de AUR
arch.config.aur=Paquetes de AUR
arch.config.aur.tip=Permite gestionar paquetes del AUR. git debe estar instalado.
arch.config.aur_rebuild_detector=Verificar necesidad de reinstalación {}
arch.config.aur_rebuild_detector.tip=Verifica si los paquetes creados con versiones antiguas de bibliotecas necesitan ser reconstruidos. Si es necesario reconstruir un paquete, el será marcado para actualización ({} debe estar instalado)
arch.config.automatch_providers=Autodefinir proveedores de dependencia
arch.config.automatch_providers.tip=Elige automáticamente qué proveedor se usará para una dependencia de paquete cuando ambos nombres son iguales.
arch.config.aur_build_dir=Directorio de compilación (AUR)
@@ -204,6 +206,7 @@ arch.missing_deps_found=Dependencias faltantes para {}
arch.mthread_downloaded.error.cache_dir=No fue posible crear el directorio de caché {}
arch.mthread_downloaded.error.cancelled=Operación cancelada
arch.optdeps.checking=Verificando las dependencias opcionales de {}
arch.package.requires_rebuild=Necesita ser reinstalado
arch.providers=proveedores
arch.substatus.conflicts=Verificando conflictos
arch.substatus.disk_space=Verificando espacio disponible en disco

View File

@@ -37,6 +37,8 @@ arch.checking.missing_deps=Vérification des dépendances manquantes de {}
arch.clone=Copie du dépôt AUR {}
arch.config.aur=Paquêts AUR
arch.config.aur.tip=Permet la gestion des paquets AUR. git doit être installé.
arch.config.aur_rebuild_detector=Check reinstallation need {}
arch.config.aur_rebuild_detector.tip=It checks if packages built with old library versions require to be rebuilt. If a package needs to be rebuilt, it will be marked for update ({} must be installed)
arch.config.automatch_providers=Définition automatique des fournisseurs de dépendances
arch.config.automatch_providers.tip=Choisit automatiquement le fournisseur de dépendances d'un paquet en cas de noms identiques
arch.config.aur_build_dir=Répertoire de compilation (AUR)
@@ -204,6 +206,7 @@ arch.missing_deps_found=Dépendances manquantes pour {}
arch.mthread_downloaded.error.cache_dir=Impossible de créer le dossier de cache {}
arch.mthread_downloaded.error.cancelled=Operation annulée
arch.optdeps.checking=Verification des dépendances optionnelles de {}
arch.package.requires_rebuild=It needs to be reinstalled
arch.providers=fournisseurs
arch.substatus.conflicts=Verification des conflits
arch.substatus.disk_space=Verification de l'espace disque disponible

View File

@@ -37,6 +37,8 @@ arch.checking.missing_deps=Verifica delle dipendenze mancanti di {}
arch.clone=Clonazione del repository AUR {}
arch.config.aur=AUR packages
arch.config.aur.tip=It allows to manage AUR packages. git must be installed.
arch.config.aur_rebuild_detector=Check reinstallation need {}
arch.config.aur_rebuild_detector.tip=It checks if packages built with old library versions require to be rebuilt. If a package needs to be rebuilt, it will be marked for update ({} must be installed)
arch.config.automatch_providers=Auto-define dependency providers
arch.config.automatch_providers.tip=It automatically chooses which provider will be used for a package dependency when both names are equal.
arch.config.aur_build_dir=Build directory (AUR)
@@ -204,6 +206,7 @@ arch.missing_deps_found=Dipendenze mancanti per {}
arch.mthread_downloaded.error.cache_dir=It was not possible to create the cache directory {}
arch.mthread_downloaded.error.cancelled=Operation cancelled
arch.optdeps.checking=Verifica di {} dipendenze opzionali
arch.package.requires_rebuild=It needs to be reinstalled
arch.providers=providers
arch.substatus.conflicts=Checking for conflicts
arch.substatus.disk_space=Checking available disk space

View File

@@ -37,6 +37,8 @@ arch.checking.missing_deps=Verificando dependências ausentes de {}
arch.clone=Clonando o repositório {} do AUR
arch.config.aur=Pacotes do AUR
arch.config.aur.tip=Permite gerenciar pacotes dos AUR. git precisa estar instalado.
arch.config.aur_rebuild_detector=Verificar necessidade de reinstalação {}
arch.config.aur_rebuild_detector.tip=Verifica se pacotes construídos com versões antigas de bibliotecas precisam ser reconstruídas.Se um pacote precisa ser reconstruído, ele será marcado para atualizar ({} precisa estar instalado).
arch.config.automatch_providers=Auto-definir provedores de dependências
arch.config.automatch_providers.tip=Escolhe automaticamente qual provedor será utilizado para determinada dependência de um pacote caso os nomes de ambos sejam iguais.
arch.config.aur_build_dir=Diretório de construção (AUR)
@@ -203,6 +205,7 @@ arch.missing_deps_found=Dependencias ausentes para {}
arch.mthread_downloaded.error.cache_dir=Não foi possível criar o diretório para cache {}
arch.mthread_downloaded.error.cancelled=Operação cancelada
arch.optdeps.checking=Verificando as dependências opcionais de {}
arch.package.requires_rebuild=Precisa ser reinstalado
arch.providers=provedores
arch.substatus.conflicts=Verificando conflitos
arch.substatus.disk_space=Verificando espaço disponível em disco

View File

@@ -37,6 +37,8 @@ arch.checking.missing_deps=Проверка отсутствующих зави
arch.clone=Клонирование AUR-репозитория {}
arch.config.aur=пакеты AUR
arch.config.aur.tip=Это позволяет управлять пакетами AUR. git должен быть установлен.
arch.config.aur_rebuild_detector=Check reinstallation need {}
arch.config.aur_rebuild_detector.tip=It checks if packages built with old library versions require to be rebuilt. If a package needs to be rebuilt, it will be marked for update ({} must be installed)
arch.config.automatch_providers=Auto-define dependency providers
arch.config.automatch_providers.tip=It automatically chooses which provider will be used for a package dependency when both names are equal.
arch.config.aur_build_dir=Build directory (AUR)
@@ -204,6 +206,7 @@ arch.missing_deps_found=Отсутствуют зависимости для {}
arch.mthread_downloaded.error.cache_dir=It was not possible to create the cache directory {}
arch.mthread_downloaded.error.cancelled=Operation cancelled
arch.optdeps.checking=Проверка необязательных обязательных зависимостей {}
arch.package.requires_rebuild=It needs to be reinstalled
arch.providers=providers
arch.substatus.conflicts=Checking for conflicts
arch.substatus.disk_space=Checking available disk space

View File

@@ -37,6 +37,8 @@ arch.checking.missing_deps={} eksik bağımlılıkları kontrol ediliyor
arch.clone=AUR deposu kopyalanıyor {}
arch.config.aur=AUR paketleri
arch.config.aur.tip=AUR paketlerinin yönetilmesine izin verir. git yüklenmeli.
arch.config.aur_rebuild_detector=Check reinstallation need {}
arch.config.aur_rebuild_detector.tip=It checks if packages built with old library versions require to be rebuilt. If a package needs to be rebuilt, it will be marked for update ({} must be installed)
arch.config.automatch_providers=Auto-define dependency providers
arch.config.automatch_providers.tip=It automatically chooses which provider will be used for a package dependency when both names are equal.
arch.config.aur_build_dir=Build directory (AUR)
@@ -204,6 +206,7 @@ arch.missing_deps_found={} için eksik bağımlılıklar
arch.mthread_downloaded.error.cache_dir=It was not possible to create the cache directory {}
arch.mthread_downloaded.error.cancelled=Operation cancelled
arch.optdeps.checking={} İsteğe bağlı bağımlılıkları kontrol et
arch.package.requires_rebuild=It needs to be reinstalled
arch.providers=sağlayıcılar
arch.substatus.conflicts=Checking for conflicts
arch.substatus.disk_space=Checking available disk space

View File

@@ -379,7 +379,7 @@ class PackagesTable(QTableWidget):
if pkg.model.update and not pkg.model.is_update_ignored():
label_version.setProperty('update', 'true')
tooltip = self.i18n['version.installed_outdated']
tooltip = pkg.model.get_update_tip() or self.i18n['version.installed_outdated']
if pkg.model.is_update_ignored():
label_version.setProperty('ignored', 'true')