mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-06 22:54:16 +02:00
[view.window] refactoring: upgrade logs
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import logging
|
||||
import operator
|
||||
import os.path
|
||||
import time
|
||||
import traceback
|
||||
from pathlib import Path
|
||||
@@ -1154,20 +1155,10 @@ class ManageWindow(QWidget):
|
||||
self._finish_action()
|
||||
|
||||
if res.get('id'):
|
||||
output = self.textarea_details.toPlainText()
|
||||
|
||||
if output:
|
||||
try:
|
||||
Path(UpgradeSelected.UPGRADE_LOGS_DIR).mkdir(parents=True, exist_ok=True)
|
||||
logs_path = '{}/{}.log'.format(UpgradeSelected.UPGRADE_LOGS_DIR, res['id'])
|
||||
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'])))
|
||||
log_msg = '* ' + self.i18n['console.operation_log'].format(path=f'"{logs_path}"')
|
||||
self.textarea_details.appendPlainText(log_msg)
|
||||
except:
|
||||
traceback.print_exc()
|
||||
self._write_operation_logs('upgrade', custom_log_file=f"{UpgradeSelected.UPGRADE_LOGS_DIR}/{res['id']}.log")
|
||||
sum_log_file = UpgradeSelected.SUMMARY_FILE.format(res['id'])
|
||||
summ_msg = '* ' + self.i18n['console.upgrade_summary'].format(path=f'"{sum_log_file}"')
|
||||
self.textarea_details.appendPlainText(summ_msg)
|
||||
|
||||
if res['success']:
|
||||
self.comp_manager.remove_saved_state(ACTION_UPGRADE)
|
||||
@@ -1388,27 +1379,36 @@ class ManageWindow(QWidget):
|
||||
self.thread_install.root_pwd = pwd
|
||||
self.thread_install.start()
|
||||
|
||||
def _write_operation_logs(self, type_: str, pkg: PackageView):
|
||||
def _write_operation_logs(self, type_: str, pkg: Optional[PackageView] = None,
|
||||
custom_log_file: Optional[str] = None):
|
||||
|
||||
console_output = self.textarea_details.toPlainText()
|
||||
|
||||
if console_output:
|
||||
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
|
||||
if custom_log_file:
|
||||
log_dir = os.path.dirname(custom_log_file)
|
||||
log_file = custom_log_file
|
||||
else:
|
||||
log_dir = f"{LOGS_DIR}/{type_}"
|
||||
if pkg:
|
||||
log_dir = f"{log_dir}/{pkg.model.get_type()}/{pkg.model.name}"
|
||||
|
||||
log_file = f'{log_path}/{int(time.time())}.log'
|
||||
log_file = f'{log_dir}/{int(time.time())}.log'
|
||||
|
||||
try:
|
||||
Path(log_dir).mkdir(parents=True, exist_ok=True)
|
||||
except OSError:
|
||||
self.logger.error(f"Could not create the operation log directory '{log_dir}'")
|
||||
return
|
||||
|
||||
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}'")
|
||||
self.logger.error(f"Could not write the operation log to file '{log_file}'")
|
||||
return
|
||||
|
||||
log_msg = '* ' + self.i18n['console.operation_log'].format(path=f'"{log_file}"')
|
||||
log_msg = '\n* ' + self.i18n['console.operation_log'].format(path=f'"{log_file}"')
|
||||
self.textarea_details.appendPlainText(log_msg)
|
||||
|
||||
def _finish_install(self, res: dict):
|
||||
|
||||
@@ -201,6 +201,7 @@ clean=netejar
|
||||
close=tanca
|
||||
confirmation=confirmació
|
||||
console.operation_log=The operation logs can be found at {path}
|
||||
console.upgrade_summary=The upgrade summary can be found at {path}
|
||||
continue=continua
|
||||
copy=copia
|
||||
core.config.backup=Enabled
|
||||
|
||||
@@ -200,6 +200,7 @@ clean=Bereinigen
|
||||
close=Schließen
|
||||
confirmation=Bestätigung
|
||||
console.operation_log=The operation logs can be found at {path}
|
||||
console.upgrade_summary=The upgrade summary can be found at {path}
|
||||
continue=Fortfahren
|
||||
copy=Kopieren
|
||||
core.config.backup=Enabled
|
||||
|
||||
@@ -202,6 +202,7 @@ clean=clean
|
||||
close=close
|
||||
confirmation=confirmation
|
||||
console.operation_log=The operation logs can be found at {path}
|
||||
console.upgrade_summary=The upgrade summary can be found at {path}
|
||||
continue=continue
|
||||
copy=copy
|
||||
core.config.backup.downgrade=Before downgrading
|
||||
|
||||
@@ -201,6 +201,7 @@ clean=limpiar
|
||||
close=cerrar
|
||||
confirmation=confirmación
|
||||
console.operation_log=Los registros de la operación se encuentran en {path}
|
||||
console.upgrade_summary=El resumen de actualización se encurentra en {path}
|
||||
continue=continuar
|
||||
copy=copiar
|
||||
core.config.backup=Habilitada
|
||||
|
||||
@@ -200,6 +200,7 @@ clean=vider
|
||||
close=fermer
|
||||
confirmation=confirmation
|
||||
console.operation_log=The operation logs can be found at {path}
|
||||
console.upgrade_summary=The upgrade summary can be found at {path}
|
||||
continue=continuer
|
||||
copy=copier
|
||||
core.config.backup.downgrade=Avant de downgrader
|
||||
|
||||
@@ -200,6 +200,7 @@ clean=pulire
|
||||
close=vicino
|
||||
confirmation=conferma
|
||||
console.operation_log=The operation logs can be found at {path}
|
||||
console.upgrade_summary=The upgrade summary can be found at {path}
|
||||
continue=continua
|
||||
copy=copia
|
||||
core.config.backup=Enabled
|
||||
|
||||
@@ -200,6 +200,7 @@ clean=limpar
|
||||
close=fechar
|
||||
confirmation=confirmação
|
||||
console.operation_log=Os registros da operação podem ser encontrados em {path}
|
||||
console.upgrade_summary=O resumo da atualização se encontra em {path}
|
||||
continue=continuar
|
||||
copy=copiar
|
||||
core.config.backup.downgrade=Antes de reverter versão
|
||||
|
||||
@@ -200,6 +200,7 @@ clean=Очистка
|
||||
close=Закрыть
|
||||
confirmation=Подтверждение
|
||||
console.operation_log=The operation logs can be found at {path}
|
||||
console.upgrade_summary=The upgrade summary can be found at {path}
|
||||
continue=Продолжить
|
||||
copy=Копировать
|
||||
core.config.backup=Enabled
|
||||
|
||||
@@ -200,6 +200,7 @@ clean=temizle
|
||||
close=kapat
|
||||
confirmation=onayla
|
||||
console.operation_log=The operation logs can be found at {path}
|
||||
console.upgrade_summary=The upgrade summary can be found at {path}
|
||||
continue=devam
|
||||
copy=kopyala
|
||||
core.config.backup.downgrade=Önce sürüm düşürülüyor
|
||||
|
||||
Reference in New Issue
Block a user