Move factory reset to Uranium

This way it can be called from other crash handling routines there too, such as ConfigurationErrorMessage which may be triggered by arbitrary configuration errors in Uranium.

Contributes to issue CURA-5045.
This commit is contained in:
Ghostkeeper 2018-03-28 08:43:46 +02:00
parent 2214a5f40a
commit fce703536b
No known key found for this signature in database
GPG key ID: 5252B696FB5E7C7A

View file

@ -132,59 +132,7 @@ class CrashHandler:
## Backup the current resource directories and create clean ones. ## Backup the current resource directories and create clean ones.
def _backupAndStartClean(self): def _backupAndStartClean(self):
from cura.CuraVersion import CuraVersion Resources.factoryReset()
# The early crash may happen before those information is set in Resources, so we need to set them here to
# make sure that Resources can find the correct place.
Resources.ApplicationIdentifier = "cura"
Resources.ApplicationVersion = CuraVersion
config_path = Resources.getConfigStoragePath()
data_path = Resources.getDataStoragePath()
cache_path = Resources.getCacheStoragePath()
folders_to_backup = []
folders_to_remove = [] # only cache folder needs to be removed
folders_to_backup.append(config_path)
if data_path != config_path:
folders_to_backup.append(data_path)
# Only remove the cache folder if it's not the same as data or config
if cache_path not in (config_path, data_path):
folders_to_remove.append(cache_path)
for folder in folders_to_remove:
shutil.rmtree(folder, ignore_errors = True)
for folder in folders_to_backup:
base_name = os.path.basename(folder)
root_dir = os.path.dirname(folder)
import datetime
date_now = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
idx = 0
file_name = base_name + "_" + date_now
zip_file_path = os.path.join(root_dir, file_name + ".zip")
while os.path.exists(zip_file_path):
idx += 1
file_name = base_name + "_" + date_now + "_" + idx
zip_file_path = os.path.join(root_dir, file_name + ".zip")
try:
# only create the zip backup when the folder exists
if os.path.exists(folder):
# remove the .zip extension because make_archive() adds it
zip_file_path = zip_file_path[:-4]
shutil.make_archive(zip_file_path, "zip", root_dir = root_dir, base_dir = base_name)
# remove the folder only when the backup is successful
shutil.rmtree(folder, ignore_errors = True)
# create an empty folder so Resources will not try to copy the old ones
os.makedirs(folder, 0o0755, exist_ok=True)
except Exception as e:
Logger.logException("e", "Failed to backup [%s] to file [%s]", folder, zip_file_path)
if not self.has_started:
print("Failed to backup [%s] to file [%s]: %s", folder, zip_file_path, e)
self.early_crash_dialog.close() self.early_crash_dialog.close()
def _showConfigurationFolder(self): def _showConfigurationFolder(self):