From 4960cfbaa8918000b803c1d4ce0b60ce3cab4d4c Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Sat, 6 Jun 2020 17:22:17 -0300 Subject: [PATCH] [fix][arch] not displaying 'removing' substatus during the upgrade process --- CHANGELOG.md | 1 + bauh/gems/arch/controller.py | 16 ++++++++++++--- bauh/gems/arch/output.py | 38 +++++++++++++++++++++++------------ bauh/view/resources/locale/ca | 1 + bauh/view/resources/locale/de | 1 + bauh/view/resources/locale/en | 1 + bauh/view/resources/locale/es | 2 ++ bauh/view/resources/locale/it | 1 + bauh/view/resources/locale/pt | 1 + bauh/view/resources/locale/ru | 1 + bauh/view/resources/locale/tr | 1 + 11 files changed, 48 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 849acfb2..8354e3d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Arch - uninstall: not checking if the are other installed providers for the target package - not recursively asking for dependencies providers when installing / upgrading + - not displaying "removing" substatus during the upgrade process - UI - table overwrite effect when updating its content diff --git a/bauh/gems/arch/controller.py b/bauh/gems/arch/controller.py index f1260193..61791338 100644 --- a/bauh/gems/arch/controller.py +++ b/bauh/gems/arch/controller.py @@ -851,15 +851,25 @@ class ArchManager(SoftwareManager): if requirements.to_remove: to_remove_names = {r.pkg.name for r in requirements.to_remove} + output_handler = TransactionStatusHandler(watcher=handler.watcher, + i18n=self.i18n, + pkgs_to_sync=0, + logger=self.logger, + pkgs_to_remove=len(to_remove_names)) + output_handler.start() try: - success = handler.handle(pacman.remove_several(to_remove_names, root_password)) + success = handler.handle(pacman.remove_several(to_remove_names, root_password), output_handler=output_handler.handle) if not success: self.logger.error("Could not remove packages: {}".format(', '.join(to_remove_names))) + output_handler.stop_working() + output_handler.join() return False except: self.logger.error("An error occured while removing packages: {}".format(', '.join(to_remove_names))) traceback.print_exc() + output_handler.stop_working() + output_handler.join() return False if repo_pkgs: @@ -1305,7 +1315,7 @@ class ArchManager(SoftwareManager): return True - def _install_deps(self, context: TransactionContext, deps: List[Tuple[str, str]]) -> Iterable[str]: + def _install_deps(self, context: TransactionContext, deps: List[Tuple[str, str]]) -> Iterable[str]: """ :param pkgs_repos: :param root_password: @@ -1355,7 +1365,7 @@ class ArchManager(SoftwareManager): except ArchDownloadException: return False - status_handler = TransactionStatusHandler(watcher=context.watcher, i18n=self.i18n, npkgs=len(repo_dep_names), + status_handler = TransactionStatusHandler(watcher=context.watcher, i18n=self.i18n, pkgs_to_sync=len(repo_dep_names), logger=self.logger, percentage=len(repo_deps) > 1, downloading=downloaded) status_handler.start() installed, _ = context.handler.handle_simple(pacman.install_as_process(pkgpaths=repo_dep_names, diff --git a/bauh/gems/arch/output.py b/bauh/gems/arch/output.py index 3f9efd42..17d68f44 100644 --- a/bauh/gems/arch/output.py +++ b/bauh/gems/arch/output.py @@ -9,15 +9,17 @@ from bauh.view.util.translation import I18n class TransactionStatusHandler(Thread): - def __init__(self, watcher: ProcessWatcher, i18n: I18n, npkgs: int, logger: logging.Logger, - percentage: bool = True, downloading: int = 0): + def __init__(self, watcher: ProcessWatcher, i18n: I18n, pkgs_to_sync: int, logger: logging.Logger, + percentage: bool = True, downloading: int = 0, pkgs_to_remove: int = 0): super(TransactionStatusHandler, self).__init__(daemon=True) self.watcher = watcher self.i18n = i18n - self.npkgs = npkgs + self.pkgs_to_sync = pkgs_to_sync + self.pkgs_to_remove = pkgs_to_remove self.downloading = downloading self.upgrading = 0 self.installing = 0 + self.removing = 0 self.outputs = [] self.work = True self.logger = logger @@ -32,7 +34,7 @@ class TransactionStatusHandler(Thread): def gen_percentage(self) -> str: if self.percentage: performed = self.downloading + self.upgrading + self.installing - return '({0:.2f}%) '.format((performed / (2 * self.npkgs)) * 100) + return '({0:.2f}%) '.format((performed / (2 * self.pkgs_to_sync)) * 100) else: return '' @@ -41,32 +43,42 @@ class TransactionStatusHandler(Thread): def _handle(self, output: str) -> bool: if output: + if output.startswith('removing'): + if self.pkgs_to_remove > 0: + self.removing += 1 + + self.watcher.change_substatus( + '[{}/{}] {} {}'.format(self.removing, self.pkgs_to_remove, + self.i18n['uninstalling'].capitalize(), output.split(' ')[1].strip())) + else: + self.watcher.change_substatus('{} {}'.format(self.i18n['uninstalling'].capitalize(), output.split(' ')[1].strip())) + if output.startswith('downloading'): - if self.downloading < self.npkgs: + if self.downloading < self.pkgs_to_sync: perc = self.gen_percentage() self.downloading += 1 - self.watcher.change_substatus('{}[{}/{}] {} {} {}'.format(perc, self.downloading, self.npkgs, bold('[pacman]'), + self.watcher.change_substatus('{}[{}/{}] {} {} {}'.format(perc, self.downloading, self.pkgs_to_sync, bold('[pacman]'), self.i18n['downloading'].capitalize(), output.split(' ')[1].strip())) elif output.startswith('upgrading'): - if self.get_performed() < self.npkgs: + if self.get_performed() < self.pkgs_to_sync: perc = self.gen_percentage() self.upgrading += 1 performed = self.upgrading + self.installing - if performed <= self.npkgs: - self.watcher.change_substatus('{}[{}/{}] {} {}'.format(perc, self.upgrading, self.npkgs, + if performed <= self.pkgs_to_sync: + self.watcher.change_substatus('{}[{}/{}] {} {}'.format(perc, self.upgrading, self.pkgs_to_sync, self.i18n['manage_window.status.upgrading'].capitalize(), output.split(' ')[1].strip())) elif output.startswith('installing'): - if self.get_performed() < self.npkgs: + if self.get_performed() < self.pkgs_to_sync: perc = self.gen_percentage() self.installing += 1 performed = self.upgrading + self.installing - if performed <= self.npkgs: - self.watcher.change_substatus('{}[{}/{}] {} {}'.format(perc, self.installing, self.npkgs, + if performed <= self.pkgs_to_sync: + self.watcher.change_substatus('{}[{}/{}] {} {}'.format(perc, self.installing, self.pkgs_to_sync, self.i18n['manage_window.status.installing'].capitalize(), output.split(' ')[1].strip())) else: @@ -83,7 +95,7 @@ class TransactionStatusHandler(Thread): if performed == 0 and self.downloading > 0: self.watcher.change_substatus('') - elif performed == self.npkgs: + elif performed == self.pkgs_to_sync: self.watcher.change_substatus(self.i18n['finishing'].capitalize()) return False diff --git a/bauh/view/resources/locale/ca b/bauh/view/resources/locale/ca index 775ccdb8..1990d2c6 100644 --- a/bauh/view/resources/locale/ca +++ b/bauh/view/resources/locale/ca @@ -385,6 +385,7 @@ task.download_categories=Download de categories [ {} ] type=tipus uninstall=desinstal·la uninstalled=desinstal·lada +uninstalling=uninstalling unknown=desconegut updates=actualitzacions user=usuari diff --git a/bauh/view/resources/locale/de b/bauh/view/resources/locale/de index a6828238..552ca506 100644 --- a/bauh/view/resources/locale/de +++ b/bauh/view/resources/locale/de @@ -384,6 +384,7 @@ task.download_categories=Downloading categories [ {} ] type=Typ uninstall=Deinstallation uninstalled=deinstalliert +uninstalling=uninstalling unknown=unbekannt updates=Updates user=Benutzer diff --git a/bauh/view/resources/locale/en b/bauh/view/resources/locale/en index 98a018b2..b16ee37a 100644 --- a/bauh/view/resources/locale/en +++ b/bauh/view/resources/locale/en @@ -384,6 +384,7 @@ task.download_categories=Downloading categories [ {} ] type=type uninstall=uninstall uninstalled=uninstalled +uninstalling=uninstalling unknown=unknown updates=updates user=user diff --git a/bauh/view/resources/locale/es b/bauh/view/resources/locale/es index 0e8461b2..cc530de3 100644 --- a/bauh/view/resources/locale/es +++ b/bauh/view/resources/locale/es @@ -363,6 +363,7 @@ prepare_panel.title.start=Inicializando proceed=continuar publisher=publicador publisher.verified=verificado +removing=removing repository=repositorio screenshots.bt_back.label=anterior screenshots.bt_next.label=siguiente @@ -385,6 +386,7 @@ task.download_categories=Descargando categorías [ {} ] type=tipo uninstall=desinstalar uninstalled=desinstalada +uninstalling=desinstalando unknown=desconocido updates=actualizaciones user=usuario diff --git a/bauh/view/resources/locale/it b/bauh/view/resources/locale/it index 5549fa14..07c378f3 100644 --- a/bauh/view/resources/locale/it +++ b/bauh/view/resources/locale/it @@ -387,6 +387,7 @@ task.download_categories=Download delle categorie [ {} ] type=tipe uninstall=Disinstalla uninstalled=disinstallato +uninstalling=uninstalling unknown=sconosciuto updates=aggiornamenti user=utente diff --git a/bauh/view/resources/locale/pt b/bauh/view/resources/locale/pt index fbd2b894..9d7894c4 100644 --- a/bauh/view/resources/locale/pt +++ b/bauh/view/resources/locale/pt @@ -384,6 +384,7 @@ task.download_categories=Baixando categorias [ {} ] type=tipo uninstall=desinstalar uninstalled=desinstalado +uninstalling=desinstalando unknown=desconhecido updates=atualizações user=usuário diff --git a/bauh/view/resources/locale/ru b/bauh/view/resources/locale/ru index bb81f40f..636fc8f0 100644 --- a/bauh/view/resources/locale/ru +++ b/bauh/view/resources/locale/ru @@ -384,6 +384,7 @@ task.download_categories=Downloading categories [ {} ] type=Тип uninstall=Деинсталляция uninstalled=Деинсталлировано +uninstalling=uninstalling unknown=неизвестный updates=Обновления user=Пользователь diff --git a/bauh/view/resources/locale/tr b/bauh/view/resources/locale/tr index 510bfb70..3ddcd7f2 100644 --- a/bauh/view/resources/locale/tr +++ b/bauh/view/resources/locale/tr @@ -384,6 +384,7 @@ task.download_categories=Kategoriler indiriliyor [ {} ] type=tür uninstall=kaldır uninstalled=kaldırıldı +uninstalling=uninstalling unknown=bilinmeyen updates=güncellemeler user=kullanıcı