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