Make backup path always set

This commit is contained in:
Veronica Berglyd Olsen
2023-08-08 19:50:20 +02:00
parent 12897ff2e1
commit c40d910b69
6 changed files with 26 additions and 38 deletions
+6 -12
View File
@@ -416,14 +416,6 @@ class NWProject(QObject):
logger.info("Backing up project")
self.mainGui.setStatus(self.tr("Backing up project ..."))
backupPath = CONFIG.backupPath()
if not isinstance(backupPath, Path):
self.mainGui.makeAlert(self.tr(
"Cannot backup project because no valid backup path is set. "
"Please set a valid backup location in Preferences."
), level=nwAlert.ERROR)
return False
if not self._data.name:
self.mainGui.makeAlert(self.tr(
"Cannot backup project because no project name is set. "
@@ -432,6 +424,7 @@ class NWProject(QObject):
return False
cleanName = makeFileNameSafe(self._data.name)
backupPath = CONFIG.backupPath()
baseDir = backupPath / cleanName
try:
baseDir.mkdir(exist_ok=True)
@@ -444,11 +437,12 @@ class NWProject(QObject):
timeStamp = formatTimeStamp(time(), fileSafe=True)
archName = baseDir / f"{cleanName} {timeStamp}.zip"
if self._storage.zipIt(archName, compression=2):
size = archName.stat().st_size
size = formatInt(archName.stat().st_size)
if doNotify:
self.mainGui.makeAlert(self.tr(
"Backup archive file written to: {0} [{1}B]"
).format(str(archName), formatInt(size)))
self.mainGui.makeAlert(
self.tr("Created a backup of your project of size {0}B.").format(size),
info=self.tr("Path: {0}").format(str(backupPath))
)
else:
self.mainGui.makeAlert(self.tr(
"Could not write backup archive."