show restore errors in notification after startup

This commit is contained in:
avollkopf 2024-05-31 16:30:35 +02:00
parent 6cc4d3e19b
commit e7c7d85731
3 changed files with 27 additions and 5 deletions

View file

@ -1,3 +1,3 @@
__version__ = "4.4.1.a14" __version__ = "4.4.1.a15"
__codename__ = "Yeast Starter" __codename__ = "Yeast Starter"

View file

@ -87,12 +87,22 @@ class ConfigFolder:
self.recursive_chown(output_path, owner, group) self.recursive_chown(output_path, owner, group)
print("Removing backup file") print("Removing backup file")
os.remove(backupfile) os.remove(backupfile)
print("contents of restored_config.zip file have been restored.") Line1="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'.") Line2="In case of a partial backup you will still be prompted to run 'cbpi setup'."
print(Line1)
print(Line2)
else: else:
zip.close() zip.close()
print("Wrong Content in zip file. No restore possible") Line1="Wrong Content in zip file. No restore possible"
print(f'These files are missing {missing_content}') 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") print("renaming zip file so it will be ignored on the next start")
try: try:
os.rename(backupfile, os.path.join(self.configFolderPath, "UNRESTORABLE_restored_config.zip")) os.rename(backupfile, os.path.join(self.configFolderPath, "UNRESTORABLE_restored_config.zip"))

View file

@ -5,6 +5,7 @@ from cbpi.api import *
import logging import logging
import shortuuid import shortuuid
from datetime import datetime from datetime import datetime
import os
class NotificationController: class NotificationController:
def __init__(self, cbpi): def __init__(self, cbpi):
@ -19,6 +20,17 @@ class NotificationController:
self.notifications = [] self.notifications = []
self.update_key="notificationupdate" self.update_key="notificationupdate"
self.sorting=False 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): def notify_log_event(self, record):
NOTIFY_ON_ERROR = self.cbpi.config.get("NOTIFY_ON_ERROR", "No") NOTIFY_ON_ERROR = self.cbpi.config.get("NOTIFY_ON_ERROR", "No")