From e7c7d85731be13a81f1a858a07893e8b711b53da Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Fri, 31 May 2024 16:30:35 +0200 Subject: [PATCH] show restore errors in notification after startup --- cbpi/__init__.py | 2 +- cbpi/configFolder.py | 18 ++++++++++++++---- cbpi/controller/notification_controller.py | 12 ++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index a616c03..48db3db 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.4.1.a14" +__version__ = "4.4.1.a15" __codename__ = "Yeast Starter" diff --git a/cbpi/configFolder.py b/cbpi/configFolder.py index bbfc51b..4d354b0 100644 --- a/cbpi/configFolder.py +++ b/cbpi/configFolder.py @@ -87,12 +87,22 @@ class ConfigFolder: self.recursive_chown(output_path, owner, group) print("Removing backup file") os.remove(backupfile) - print("contents of restored_config.zip file have been restored.") - print("in case of a partial backup you will still be prompted to run 'cbpi setup'.") + Line1="Contents of restored_config.zip file have been restored." + Line2="In case of a partial backup you will still be prompted to run 'cbpi setup'." + print(Line1) + print(Line2) else: zip.close() - print("Wrong Content in zip file. No restore possible") - print(f'These files are missing {missing_content}') + Line1="Wrong Content in zip file. No restore possible" + Line2=f'These files are missing {missing_content}' + print(Line1) + print(Line2) + restorelogfile = os.path.join(self.configFolderPath, "restore_error.log") + f = open(restorelogfile, "w") + f.write(Line1+"\n") + f.write(Line2+"\n") + f.close() + print("renaming zip file so it will be ignored on the next start") try: os.rename(backupfile, os.path.join(self.configFolderPath, "UNRESTORABLE_restored_config.zip")) diff --git a/cbpi/controller/notification_controller.py b/cbpi/controller/notification_controller.py index 5cbd20c..212ab0e 100644 --- a/cbpi/controller/notification_controller.py +++ b/cbpi/controller/notification_controller.py @@ -5,6 +5,7 @@ from cbpi.api import * import logging import shortuuid from datetime import datetime +import os class NotificationController: def __init__(self, cbpi): @@ -19,6 +20,17 @@ class NotificationController: self.notifications = [] self.update_key="notificationupdate" self.sorting=False + self.check_startup_message() + + def check_startup_message(self): + self.restore_error = self.cbpi.config_folder.get_file_path("restore_error.log") + try: + with open(self.restore_error) as f: + for line in f: + self.notifications.insert(0,[f'{datetime.now().strftime("%Y-%m-%d %H:%M:%S")}: Restore Error | {line}']) + os.remove(self.restore_error) + except Exception as e: + pass def notify_log_event(self, record): NOTIFY_ON_ERROR = self.cbpi.config.get("NOTIFY_ON_ERROR", "No")