Skip to content

Commit

Permalink
Rename clear_all_thumbnails to clear_temporary_files
Browse files Browse the repository at this point in the history
- clear_all_thumbnails was an unmaintainable name for a function that
  not only deleted three different types of working files, but ALSO
  deleted the (previous) project data backup!
- Now uses info.get_default_path() to avoid hard-coding directory
  names under `info.USER_PATH`
  • Loading branch information
ferdnyc committed Dec 9, 2021
1 parent 15392cd commit 4f0b596
Showing 1 changed file with 25 additions and 31 deletions.
56 changes: 25 additions & 31 deletions src/windows/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def create_lock_file(self):
self.destroy_lock_file()
else:
# Normal startup, clear thumbnails
self.clear_all_thumbnails()
self.clear_temporary_files()

# Reset Sentry component (it can be temporarily changed to libopenshot during
# the call to libopenshot_crash_recovery above)
Expand Down Expand Up @@ -288,7 +288,7 @@ def actionNew_trigger(self):
return

# Clear any previous thumbnails
self.clear_all_thumbnails()
self.clear_temporary_files()

# clear data and start new project
app.project.load("")
Expand Down Expand Up @@ -417,10 +417,10 @@ def save_project(self, file_path):
# Load recent projects again
self.load_recent_menu()

log.info("Saved project {}".format(file_path))
log.info("Saved project %s", file_path)

except Exception as ex:
log.error("Couldn't save project %s.", file_path, exc_info=1)
log.error("Couldn't save project %s", file_path, exc_info=1)
QMessageBox.warning(self, _("Error Saving Project"), str(ex))

def open_project(self, file_path, clear_thumbnails=True):
Expand Down Expand Up @@ -461,7 +461,7 @@ def open_project(self, file_path, clear_thumbnails=True):
if os.path.exists(file_path):
# Clear any previous thumbnails
if clear_thumbnails:
self.clear_all_thumbnails()
self.clear_temporary_files()

# Load project file
app.project.load(file_path, clear_thumbnails)
Expand Down Expand Up @@ -505,37 +505,31 @@ def open_project(self, file_path, clear_thumbnails=True):
# Restore normal cursor
app.restoreOverrideCursor()

def clear_all_thumbnails(self):
def clear_temporary_files(self):
"""Clear all user thumbnails"""
try:
clear_path = os.path.join(info.USER_PATH, "thumbnail")
if os.path.exists(clear_path):
log.info("Clear all thumbnails: %s", clear_path)
shutil.rmtree(clear_path)
os.mkdir(clear_path)

# Clear any blender animations
clear_path = os.path.join(info.USER_PATH, "blender")
if os.path.exists(clear_path):
log.info("Clear all animations: %s", clear_path)
shutil.rmtree(clear_path)
os.mkdir(clear_path)

# Clear any title animations
clear_path = os.path.join(info.USER_PATH, "title")
if os.path.exists(clear_path):
log.info("Clear all titles: %s", clear_path)
shutil.rmtree(clear_path)
os.mkdir(clear_path)
for temp_dir in [
info.get_default_path("THUMBNAIL_PATH"),
info.get_default_path("BLENDER_PATH"),
info.get_default_path("TITLE_PATH"),
]:
try:
if os.path.exists(temp_dir):
shutil.rmtree(temp_dir)
log.info("Cleared temporary files: %s", temp_dir)
os.mkdir(temp_dir)
except Exception:
log.warning("Failed to clear %s", temp_dir, exc_info=1)

# Clear any backups
if os.path.exists(info.BACKUP_FILE):
log.info("Clear backup: %s", info.BACKUP_FILE)
# Remove backup file
os.unlink(info.BACKUP_FILE)
try:
# Remove backup file
os.unlink(info.BACKUP_FILE)
log.info("Cleared backup: %s", info.BACKUP_FILE)
except Exception:
log.warning("Could not delete backup file %s",
info.BACKUP_FILE, exc_info=1)

except Exception:
log.info("Failed to clear %s", clear_path, exc_info=1)

def actionOpen_trigger(self):
app = get_app()
Expand Down

0 comments on commit 4f0b596

Please sign in to comment.