Added and connected class to handle project backups
This commit is contained in:
@@ -89,6 +89,12 @@ class Config:
|
|||||||
|
|
||||||
self.spellLanguage = "en_GB"
|
self.spellLanguage = "en_GB"
|
||||||
|
|
||||||
|
# Backup
|
||||||
|
self.backupPath = None
|
||||||
|
self.backupOnClose = True
|
||||||
|
self.minBackupTime = 0
|
||||||
|
self.askBeforeBackup = True
|
||||||
|
|
||||||
# Path
|
# Path
|
||||||
self.recentList = [""]*10
|
self.recentList = [""]*10
|
||||||
|
|
||||||
@@ -184,6 +190,10 @@ class Config:
|
|||||||
self.fmtDoubleQuotes = self._parseLine(cnfParse, cnfSec, "fmtdoublequote", self.CNF_LIST, self.fmtDoubleQuotes)
|
self.fmtDoubleQuotes = self._parseLine(cnfParse, cnfSec, "fmtdoublequote", self.CNF_LIST, self.fmtDoubleQuotes)
|
||||||
self.spellLanguage = self._parseLine(cnfParse, cnfSec, "spellcheck", self.CNF_STR, self.spellLanguage)
|
self.spellLanguage = self._parseLine(cnfParse, cnfSec, "spellcheck", self.CNF_STR, self.spellLanguage)
|
||||||
|
|
||||||
|
## Backup
|
||||||
|
cnfSec = "Backup"
|
||||||
|
self.backupPath = self._parseLine(cnfParse, cnfSec, "backuppath", self.CNF_STR, self.backupPath)
|
||||||
|
|
||||||
## Path
|
## Path
|
||||||
cnfSec = "Path"
|
cnfSec = "Path"
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
@@ -240,6 +250,11 @@ class Config:
|
|||||||
cnfParse.set(cnfSec,"fmtdoublequote",self._packList(self.fmtDoubleQuotes))
|
cnfParse.set(cnfSec,"fmtdoublequote",self._packList(self.fmtDoubleQuotes))
|
||||||
cnfParse.set(cnfSec,"spellcheck", str(self.spellLanguage))
|
cnfParse.set(cnfSec,"spellcheck", str(self.spellLanguage))
|
||||||
|
|
||||||
|
## Backup
|
||||||
|
cnfSec = "Backup"
|
||||||
|
cnfParse.add_section(cnfSec)
|
||||||
|
cnfParse.set(cnfSec,"backuppath", str(self.backupPath))
|
||||||
|
|
||||||
## Path
|
## Path
|
||||||
cnfSec = "Path"
|
cnfSec = "Path"
|
||||||
cnfParse.add_section(cnfSec)
|
cnfParse.add_section(cnfSec)
|
||||||
|
|||||||
+4
-1
@@ -36,6 +36,7 @@ from nw.project.project import NWProject
|
|||||||
from nw.project.document import NWDoc
|
from nw.project.document import NWDoc
|
||||||
from nw.project.item import NWItem
|
from nw.project.item import NWItem
|
||||||
from nw.project.index import NWIndex
|
from nw.project.index import NWIndex
|
||||||
|
from nw.project.backup import NWBackup
|
||||||
from nw.tools.wordcount import countWords
|
from nw.tools.wordcount import countWords
|
||||||
from nw.theme import Theme
|
from nw.theme import Theme
|
||||||
from nw.enum import nwItemType, nwAlert
|
from nw.enum import nwItemType, nwAlert
|
||||||
@@ -209,6 +210,8 @@ class GuiMain(QMainWindow):
|
|||||||
self.closeDocument()
|
self.closeDocument()
|
||||||
if self.theProject.projChanged:
|
if self.theProject.projChanged:
|
||||||
saveOK = self.saveProject()
|
saveOK = self.saveProject()
|
||||||
|
theBackup = NWBackup(self.theProject)
|
||||||
|
theBackup.zipIt()
|
||||||
else:
|
else:
|
||||||
saveOK = True
|
saveOK = True
|
||||||
|
|
||||||
@@ -217,7 +220,7 @@ class GuiMain(QMainWindow):
|
|||||||
self.theIndex.clearIndex()
|
self.theIndex.clearIndex()
|
||||||
self.clearGUI()
|
self.clearGUI()
|
||||||
self.hasProject = False
|
self.hasProject = False
|
||||||
|
|
||||||
return saveOK
|
return saveOK
|
||||||
|
|
||||||
def openProject(self, projFile=None):
|
def openProject(self, projFile=None):
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""novelWriter Project Backup
|
||||||
|
|
||||||
|
novelWriter – Project Backup
|
||||||
|
==============================
|
||||||
|
Class handling project backups
|
||||||
|
|
||||||
|
File History:
|
||||||
|
Created: 2019-06-16 [0.1.5]
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import nw
|
||||||
|
|
||||||
|
from os import path, mkdir, listdir
|
||||||
|
from shutil import make_archive
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from nw.enum import nwAlert
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class NWBackup():
|
||||||
|
|
||||||
|
def __init__(self, theParent, theProject):
|
||||||
|
|
||||||
|
self.mainConf = nw.CONFIG
|
||||||
|
self.theParent = theParent
|
||||||
|
self.theProject = theProject
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def zipIt(self):
|
||||||
|
|
||||||
|
if self.mainConf.backupPath is None:
|
||||||
|
self.theParent.makeAlert("Cannot backup project because no backup path is set.",nwAlert.WARN)
|
||||||
|
return False
|
||||||
|
|
||||||
|
if self.theProject.projName is None:
|
||||||
|
self.theParent.makeAlert("Cannot backup project because no project name is set.",nwAlert.WARN)
|
||||||
|
return False
|
||||||
|
|
||||||
|
logger.info("Backing up project")
|
||||||
|
|
||||||
|
archName = ""
|
||||||
|
for c in self.theProject.projName:
|
||||||
|
if c.isalnum():
|
||||||
|
archName += c
|
||||||
|
|
||||||
|
archName = archName+"_"+datetime.now().strftime("%Y%m%d-%H%M%S")
|
||||||
|
baseName = path.join(self.mainConf.backupPath, archName)
|
||||||
|
|
||||||
|
try:
|
||||||
|
make_archive(
|
||||||
|
baseName, "zip",
|
||||||
|
root_dir = self.theProject.projPath,
|
||||||
|
base_dir = "."
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
self.theParent.makeAlert(["Could not write backup archive.",str(e)],nwAlert.ERROR)
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
# END Class NWBackup
|
||||||
Reference in New Issue
Block a user