Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve backup feature #1484

Merged
merged 3 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions novelwriter/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
12 changes: 6 additions & 6 deletions novelwriter/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
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
Expand Down Expand Up @@ -446,14 +446,14 @@ def backupProject(self, doNotify: bool) -> bool:
), 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):
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."
Expand Down
8 changes: 4 additions & 4 deletions tests/test_core/test_core_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down