Skip to content

Commit ba5c669

Browse files
ChsudeeptaChsudeepta
authored andcommitted
Ticket8814: Added logic to respect .zip backup when present
1 parent fe3da80 commit ba5c669

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

installation_and_upgrade/ibex_install_utils/tasks/backup_tasks.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,43 @@ def backup_checker(self) -> None:
106106
"""
107107
for path in (EPICS_PATH, PYTHON_3_PATH, GUI_PATH):
108108
path_to_backup = self._path_to_backup(path)
109-
if not os.path.exists(os.path.join(path_to_backup, "VERSION.txt")):
109+
backup_folder_exists = True
110+
backup_zip_exists = False
111+
file_to_check = 'VERSION.txt'
112+
if not os.path.exists(os.path.join(path_to_backup, file_to_check)):
113+
backup_folder_exists = False
114+
if not backup_folder_exists:
115+
backup_zip_exists = True
116+
#The backup might be in the zip files instead of folders
117+
backup_zip_file = os.path.join(path_to_backup + ".zip")
118+
if os.path.exists(backup_zip_file):
119+
#Extract the file name without extension.
120+
backup_file_name = os.path.basename(path_to_backup)
121+
with zipfile.ZipFile(backup_zip_file, 'r') as backup_ref:
122+
if not file_to_check in backup_ref.namelist():
123+
backup_zip_exists = False
124+
else:
125+
backup_zip_exists = False
126+
127+
if not backup_folder_exists and not backup_zip_exists:
110128
self.prompt.prompt_and_raise_if_not_yes(
111129
f"Error found with backup. Backup failed at '{path_to_backup}'. "
112130
"Please backup manually."
113131
)
114132

115133
for path in (SETTINGS_DIR, AUTOSAVE, EPICS_UTILS_PATH):
116-
if not os.path.exists(self._path_to_backup(path)):
134+
#Either the folder or the corresponding .zip file should exist
135+
if (not os.path.exists(self._path_to_backup(path))
136+
and not os.path.exists(self._path_to_backup(path) + ".zip")):
137+
self.prompt.prompt_and_raise_if_not_yes(
138+
f"Error found with backup. '{path}' did not back up properly. "
139+
"Please backup manually."
140+
)
141+
142+
for path in (SETTINGS_DIR, AUTOSAVE, EPICS_UTILS_PATH):
143+
#Either the folder or the corresponding .zip file should exist
144+
if (not os.path.exists(self._path_to_backup(path))
145+
and not os.path.exists(self._path_to_backup(path) + ".zip")):
117146
self.prompt.prompt_and_raise_if_not_yes(
118147
f"Error found with backup. '{path}' did not back up properly. "
119148
"Please backup manually."

0 commit comments

Comments
 (0)