Skip to content

Commit

Permalink
Gracefully skip backup if the copy path fails, red UI alerts if updat…
Browse files Browse the repository at this point in the history
…e ready

Also converting some remaining manual logging to use print_verbose
  • Loading branch information
TheDuckCow committed Jun 6, 2021
1 parent 8ba9bde commit 44bc943
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
35 changes: 26 additions & 9 deletions addon_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,11 +831,21 @@ def create_backup(self):

# Make a full addon copy, temporarily placed outside the addon folder.
if self._backup_ignore_patterns is not None:
shutil.copytree(
self._addon_root, tempdest,
ignore=shutil.ignore_patterns(*self._backup_ignore_patterns))
try:
shutil.copytree(self._addon_root, tempdest,
ignore=shutil.ignore_patterns(
*self._backup_ignore_patterns))
except:
print("Failed to create backup, still attempting update.")
self.print_trace()
return
else:
shutil.copytree(self._addon_root, tempdest)
try:
shutil.copytree(self._addon_root, tempdest)
except:
print("Failed to create backup, still attempting update.")
self.print_trace()
return
shutil.move(tempdest, local)

# Save the date for future reference.
Expand Down Expand Up @@ -1524,10 +1534,17 @@ def save_updater_json(self):
self._json["version_text"] = dict()

jpath = self.get_json_path()
outf = open(jpath, 'w')
data_out = json.dumps(self._json, indent=4)
outf.write(data_out)
outf.close()
if not os.path.isdir(os.path.dirname(jpath)):
print("State error: Directory does not exist, cannot save json: ",
os.path.basename(jpath))
return
try:
with open(jpath, 'w') as outf:
data_out = json.dumps(self._json, indent=4)
outf.write(data_out)
except:
print("Failed to open/save data to json: ", jpath)
self.print_trace()
self.print_verbose("Wrote out updater JSON settings with content:")
self.print_verbose(str(self._json))

Expand Down Expand Up @@ -1586,7 +1603,7 @@ def async_check_update(self, now, callback=None):
if callback:
self.print_verbose("Finished check update, doing callback")
callback(self._update_ready)
self.print_verbose("{} BG thread: Finished check update, no callback")
self.print_verbose("BG thread: Finished check update, no callback")

def stop_async_check_update(self):
"""Method to give impression of stopping check for update.
Expand Down
12 changes: 5 additions & 7 deletions addon_updater_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ def execute(self, context):
atr = AddonUpdaterInstallPopup.bl_idname.split(".")
getattr(getattr(bpy.ops, atr[0]), atr[1])('INVOKE_DEFAULT')
else:
if updater.verbose:
print("Doing nothing, not ready for update")
updater.print_verbose("Doing nothing, not ready for update")
return {'FINISHED'}


Expand Down Expand Up @@ -662,9 +661,7 @@ def updater_run_success_popup_handler(scene):
def updater_run_install_popup_handler(scene):
global ran_auto_check_install_popup
ran_auto_check_install_popup = True
if updater.verbose:
print("{} updater: Running the install popup handler.".format(
updater.addon))
updater.print_verbose("Running the install popup handler.")

# in case of error importing updater
if updater.invalid_updater:
Expand Down Expand Up @@ -830,8 +827,7 @@ def check_for_update_nonthreaded(self, context):
atr = AddonUpdaterInstallPopup.bl_idname.split(".")
getattr(getattr(bpy.ops, atr[0]), atr[1])('INVOKE_DEFAULT')
else:
if updater.verbose:
print("No update ready")
updater.print_verbose("No update ready")
self.report({'INFO'}, "No update ready")


Expand Down Expand Up @@ -916,7 +912,9 @@ def update_notice_box_ui(self, context):
layout = self.layout
box = layout.box()
col = box.column(align=True)
col.alert = True
col.label(text="Update ready!", icon="ERROR")
col.alert = False
col.separator()
row = col.row(align=True)
split = row.split(align=True)
Expand Down

0 comments on commit 44bc943

Please sign in to comment.