From 581f5b9d469f21f7b9d9f100e2d8d60bba179783 Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Fri, 8 Apr 2022 10:45:43 -0300 Subject: [PATCH] [view] fix: uninstall and downgrade logs are not available --- CHANGELOG.md | 1 + bauh/view/qt/window.py | 32 ++++++++++++++++++++++---------- bauh/view/resources/locale/ca | 2 +- bauh/view/resources/locale/de | 2 +- bauh/view/resources/locale/en | 2 +- bauh/view/resources/locale/es | 2 +- bauh/view/resources/locale/fr | 2 +- bauh/view/resources/locale/it | 2 +- bauh/view/resources/locale/pt | 2 +- bauh/view/resources/locale/ru | 2 +- bauh/view/resources/locale/tr | 2 +- 11 files changed, 32 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21a4124c..35fe24a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixes - General - not properly converting bit based sizes (KiB, MiB, etc...) to byte based + - uninstall and downgrade logs are not available [#255](https://github.com/vinifmor/bauh/issues/255) - Debian - info: crashing when the package size has unexpected symbols [#251](https://github.com/vinifmor/bauh/issues/251) diff --git a/bauh/view/qt/window.py b/bauh/view/qt/window.py index 20702991..d30f7190 100755 --- a/bauh/view/qt/window.py +++ b/bauh/view/qt/window.py @@ -764,6 +764,8 @@ class ManageWindow(QWidget): def _finish_uninstall(self, res: dict): self._finish_action(action_id=ACTION_UNINSTALL) + self._write_operation_logs('uninstall', res['pkg']) + if res['success']: src_pkg = res['pkg'] if self._can_notify_user(): @@ -1161,8 +1163,9 @@ class ManageWindow(QWidget): with open(logs_path, 'w+') as f: f.write(output) - self.textarea_details.appendPlainText('\n*Upgrade summary generated at: {}'.format(UpgradeSelected.SUMMARY_FILE.format(res['id']))) - self.textarea_details.appendPlainText('*Upgrade logs generated at: {}'.format(logs_path)) + self.textarea_details.appendPlainText('\n* Upgrade summary generated at: {}'.format(UpgradeSelected.SUMMARY_FILE.format(res['id']))) + log_msg = '* ' + self.i18n['console.operation_log'].format(path=f'"{logs_path}"') + self.textarea_details.appendPlainText(log_msg) except: traceback.print_exc() @@ -1246,6 +1249,7 @@ class ManageWindow(QWidget): def _finish_downgrade(self, res: dict): self._finish_action() + self._write_operation_logs('downgrade', res['app']) if res['success']: self.comp_manager.remove_saved_state(ACTION_DOWNGRADE) @@ -1384,24 +1388,32 @@ class ManageWindow(QWidget): self.thread_install.root_pwd = pwd self.thread_install.start() - def _finish_install(self, res: dict): - self._finish_action(action_id=ACTION_INSTALL) - + def _write_operation_logs(self, type_: str, pkg: PackageView): console_output = self.textarea_details.toPlainText() if console_output: - log_path = f"{LOGS_DIR}/install/{res['pkg'].model.get_type()}/{res['pkg'].model.name}" + log_path = f"{LOGS_DIR}/{type_}/{pkg.model.get_type()}/{pkg.model.name}" try: Path(log_path).mkdir(parents=True, exist_ok=True) + except OSError: + self.textarea_details.appendPlainText(f"[error] Could not create the operation log directory '{log_path}'") + return - log_file = f'{log_path}/{int(time.time())}.log' + log_file = f'{log_path}/{int(time.time())}.log' + try: with open(log_file, 'w+') as f: f.write(console_output) + except OSError: + self.textarea_details.appendPlainText(f"[error] Could not write the operation log to file '{log_file}'") + return - self.textarea_details.appendPlainText(self.i18n['console.install_logs.path'].format('"{}"'.format(log_file))) - except: - self.textarea_details.appendPlainText("[warning] Could not write install log file to '{}'".format(log_path)) + log_msg = '* ' + self.i18n['console.operation_log'].format(path=f'"{log_file}"') + self.textarea_details.appendPlainText(log_msg) + + def _finish_install(self, res: dict): + self._finish_action(action_id=ACTION_INSTALL) + self._write_operation_logs('install', res['pkg']) if res['success']: if self._can_notify_user(): diff --git a/bauh/view/resources/locale/ca b/bauh/view/resources/locale/ca index 226c0bde..075fe4b8 100644 --- a/bauh/view/resources/locale/ca +++ b/bauh/view/resources/locale/ca @@ -200,7 +200,7 @@ change=modifica clean=netejar close=tanca confirmation=confirmació -console.install_logs.path=Trobareu registres d’instal·lació a {} +console.operation_log=The operation logs can be found at {path} continue=continua copy=copia core.config.backup=Enabled diff --git a/bauh/view/resources/locale/de b/bauh/view/resources/locale/de index f255e69a..ecabb240 100644 --- a/bauh/view/resources/locale/de +++ b/bauh/view/resources/locale/de @@ -199,7 +199,7 @@ change=Anwenden clean=Bereinigen close=Schließen confirmation=Bestätigung -console.install_logs.path=Die Installationslogs befinden sich unter {} +console.operation_log=The operation logs can be found at {path} continue=Fortfahren copy=Kopieren core.config.backup=Enabled diff --git a/bauh/view/resources/locale/en b/bauh/view/resources/locale/en index 51a5dfeb..ec6d5e33 100644 --- a/bauh/view/resources/locale/en +++ b/bauh/view/resources/locale/en @@ -201,7 +201,7 @@ change=change clean=clean close=close confirmation=confirmation -console.install_logs.path=Installation logs can be found at {} +console.operation_log=The operation logs can be found at {path} continue=continue copy=copy core.config.backup.downgrade=Before downgrading diff --git a/bauh/view/resources/locale/es b/bauh/view/resources/locale/es index e0a9b0f4..efea1271 100644 --- a/bauh/view/resources/locale/es +++ b/bauh/view/resources/locale/es @@ -200,7 +200,7 @@ change=cambiar clean=limpiar close=cerrar confirmation=confirmación -console.install_logs.path=Los registros de instalación pueden encontrarse en {} +console.operation_log=Los registros de la operación se encuentran en {path} continue=continuar copy=copiar core.config.backup=Habilitada diff --git a/bauh/view/resources/locale/fr b/bauh/view/resources/locale/fr index 9bbaa211..c0686ce3 100644 --- a/bauh/view/resources/locale/fr +++ b/bauh/view/resources/locale/fr @@ -199,7 +199,7 @@ change=changement clean=vider close=fermer confirmation=confirmation -console.install_logs.path=Logs d'installation disponibles à {} +console.operation_log=The operation logs can be found at {path} continue=continuer copy=copier core.config.backup.downgrade=Avant de downgrader diff --git a/bauh/view/resources/locale/it b/bauh/view/resources/locale/it index c5958497..aa5062f7 100644 --- a/bauh/view/resources/locale/it +++ b/bauh/view/resources/locale/it @@ -199,7 +199,7 @@ change=Cambia clean=pulire close=vicino confirmation=conferma -console.install_logs.path=I registri di installazione sono disponibili all'indirizzo {} +console.operation_log=The operation logs can be found at {path} continue=continua copy=copia core.config.backup=Enabled diff --git a/bauh/view/resources/locale/pt b/bauh/view/resources/locale/pt index 9e223527..1c09ec48 100644 --- a/bauh/view/resources/locale/pt +++ b/bauh/view/resources/locale/pt @@ -199,7 +199,7 @@ change=alterar clean=limpar close=fechar confirmation=confirmação -console.install_logs.path=Os registros de instalação podem ser encontrados em {} +console.operation_log=Os registros da operação podem ser encontrados em {path} continue=continuar copy=copiar core.config.backup.downgrade=Antes de reverter versão diff --git a/bauh/view/resources/locale/ru b/bauh/view/resources/locale/ru index bc7269fe..bf2a0605 100644 --- a/bauh/view/resources/locale/ru +++ b/bauh/view/resources/locale/ru @@ -199,7 +199,7 @@ change=Изменить clean=Очистка close=Закрыть confirmation=Подтверждение -console.install_logs.path=Журналы установки можно найти по адресу {} +console.operation_log=The operation logs can be found at {path} continue=Продолжить copy=Копировать core.config.backup=Enabled diff --git a/bauh/view/resources/locale/tr b/bauh/view/resources/locale/tr index 41546b8a..6a206443 100644 --- a/bauh/view/resources/locale/tr +++ b/bauh/view/resources/locale/tr @@ -199,7 +199,7 @@ change=değiştir clean=temizle close=kapat confirmation=onayla -console.install_logs.path=Kurulum günlüklerini {} adresinde bulabilirsiniz +console.operation_log=The operation logs can be found at {path} continue=devam copy=kopyala core.config.backup.downgrade=Önce sürüm düşürülüyor