Skip to content

Commit

Permalink
show restore errors in notification after startup
Browse files Browse the repository at this point in the history
  • Loading branch information
avollkopf committed May 31, 2024
1 parent 6cc4d3e commit e7c7d85
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cbpi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "4.4.1.a14"
__version__ = "4.4.1.a15"
__codename__ = "Yeast Starter"

18 changes: 14 additions & 4 deletions cbpi/configFolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,22 @@ def check_for_setup(self):
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"))
Expand Down
12 changes: 12 additions & 0 deletions cbpi/controller/notification_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
import shortuuid
from datetime import datetime
import os
class NotificationController:

def __init__(self, cbpi):
Expand All @@ -19,6 +20,17 @@ def __init__(self, cbpi):
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")
Expand Down

0 comments on commit e7c7d85

Please sign in to comment.