From d81a90add33452735d2bb85f2d35949805555433 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Thu, 27 Jul 2023 00:08:26 +0200 Subject: [PATCH 1/3] Add project name to backup file (#1476) --- novelwriter/core/project.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/novelwriter/core/project.py b/novelwriter/core/project.py index 51cc8955..4a52d3f3 100644 --- a/novelwriter/core/project.py +++ b/novelwriter/core/project.py @@ -446,9 +446,8 @@ class NWProject(QObject): ), nwAlert.ERROR, exception=exc) return False - archName = baseDir / self.tr( - "Backup from {0}" - ).format(formatTimeStamp(time(), fileSafe=True) + ".zip") + timeStamp = formatTimeStamp(time(), fileSafe=True) + archName = baseDir / f"{cleanName} {timeStamp}.zip" if self._storage.zipIt(archName, compression=2): if doNotify: self.mainGui.makeAlert(self.tr( From ace037808fd3093a884d90a90e5d0ece412e4f6d Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Thu, 27 Jul 2023 00:09:05 +0200 Subject: [PATCH 2/3] Add backups size to pop-up dialog (#1453) --- novelwriter/common.py | 3 +-- novelwriter/core/project.py | 7 ++++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/novelwriter/common.py b/novelwriter/common.py index 5f8fedff..a325e604 100644 --- a/novelwriter/common.py +++ b/novelwriter/common.py @@ -209,8 +209,7 @@ def checkIntTuple(value: int, valid: tuple | list | set, default: int) -> int: # =============================================================================================== # def formatInt(value: int) -> str: - """Formats an integer with k, M, G etc. - """ + """Formats an integer with k, M, G etc.""" if not isinstance(value, int): return "ERR" diff --git a/novelwriter/core/project.py b/novelwriter/core/project.py index 4a52d3f3..20fb6dc2 100644 --- a/novelwriter/core/project.py +++ b/novelwriter/core/project.py @@ -46,7 +46,7 @@ from novelwriter.core.sessions import NWSessionLog from novelwriter.core.projectxml import ProjectXMLReader, ProjectXMLWriter, XMLReadState from novelwriter.core.projectdata import NWProjectData from novelwriter.common import ( - checkStringNone, formatTimeStamp, hexToInt, makeFileNameSafe, minmax + checkStringNone, formatInt, formatTimeStamp, hexToInt, makeFileNameSafe, minmax ) if TYPE_CHECKING: # pragma: no cover @@ -449,10 +449,11 @@ 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 if doNotify: self.mainGui.makeAlert(self.tr( - "Backup archive file written to: {0}" - ).format(str(archName), nwAlert.INFO)) + "Backup archive file written to: {0} [{1}B]" + ).format(str(archName), formatInt(size)), nwAlert.INFO) else: self.mainGui.makeAlert(self.tr( "Could not write backup archive." From 0c04b0ba866d56c9d4467b6031875265d251697b Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Thu, 27 Jul 2023 00:12:25 +0200 Subject: [PATCH 3/3] Update test --- tests/test_core/test_core_project.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_core/test_core_project.py b/tests/test_core/test_core_project.py index 3e0e7b11..cf76b7f7 100644 --- a/tests/test_core/test_core_project.py +++ b/tests/test_core/test_core_project.py @@ -620,12 +620,12 @@ def testCoreProject_Backup(monkeypatch, mockGUI, fncPath, tstPaths): theFiles = list((tstPaths.tmpDir / "Test Minimal").iterdir()) assert len(theFiles) in (1, 2) # Sometimes 2 due to clock tick - theZip = theFiles[-1].name - assert theZip[:12] == "Backup from " - assert theZip[-4:] == ".zip" + theZip = theFiles[-1] + assert theZip.name.startswith("Test Minimal") + assert theZip.suffix == ".zip" # Extract the archive - with ZipFile(tstPaths.tmpDir / "Test Minimal" / theZip, mode="r") as inZip: + with ZipFile(tstPaths.tmpDir / "Test Minimal" / theZip.name, mode="r") as inZip: inZip.extractall(tstPaths.tmpDir / "extract") # Check that the main project file was restored