Added code to permanently delete project documents

This commit is contained in:
Veronica K. B. Olsen
2020-02-01 14:10:48 +01:00
parent 605541c87d
commit f937ebc396
4 changed files with 96 additions and 62 deletions
+26 -9
View File
@@ -59,7 +59,7 @@ class NWDoc():
if self.theItem.parHandle == self.theProject.trashRoot:
self.docEditable = False
docDir, docFile = self._assemblePath(self.FILE_MN)
docDir, docFile = self.assemblePath(self.docHandle, self.FILE_MN)
self.fileLoc = path.join(docDir,docFile)
logger.debug("Opening document %s" % self.fileLoc)
dataDir = path.join(self.theProject.projPath, docDir)
@@ -92,7 +92,7 @@ class NWDoc():
if self.docHandle is None or not self.docEditable:
return False
docDir, docFile = self._assemblePath(self.FILE_MN)
docDir, docFile = self.assemblePath(self.docHandle, self.FILE_MN)
logger.debug("Saving document %s" % path.join(docDir,docFile))
dataPath = path.join(self.theProject.projPath, docDir)
docPath = path.join(dataPath, docFile)
@@ -124,15 +124,32 @@ class NWDoc():
return True
##
# Internal Functions
##
def deleteDocument(self, tHandle):
"""Permanently delete a document source file and its backups
from the project data folder.
"""
docDir, docFile = self.assemblePath(tHandle, self.FILE_MN)
dataPath = path.join(self.theProject.projPath, docDir)
chkList = []
chkList.append(path.join(dataPath, docFile))
chkList.append(path.join(dataPath,docFile[:-3]+"tmp"))
chkList.append(path.join(dataPath,docFile[:-3]+"bak"))
for chkFile in chkList:
if path.isfile(chkFile):
try:
unlink(chkFile)
logger.debug("Deleted: %s" % chkFile)
except Exception as e:
self.makeAlert(["Could not delete document file.",str(e)], nwAlert.ERROR)
return False
return True
def _assemblePath(self, docExt):
if self.docHandle is None:
@staticmethod
def assemblePath(tHandle, docExt):
if tHandle is None:
return None
docDir = "data_"+self.docHandle[0]
docFile = self.docHandle[1:13]+"_"+docExt
docDir = "data_"+tHandle[0]
docFile = tHandle[1:13]+"_"+docExt
return docDir, docFile
# END Class NWDoc
+10 -40
View File
@@ -13,7 +13,7 @@
import logging
import nw
from os import path, mkdir, listdir
from os import path, mkdir, listdir, unlink
from shutil import copyfile
from lxml import etree
from hashlib import sha256
@@ -369,39 +369,6 @@ class NWProject():
self.clearProject()
return True
##
# Document Methods
##
def splitDocument(self, tHandle, headerLevel, folderLevel):
"""Split a document into multiple documents under the same
header. Header level threshold determines at what level the
splitting should occur, and folders can also be created at a
certain structure level.
"""
return True
def mergeDocuments(self, handleList):
"""Merge a list of document handles into a single document.
"""
fileList = []
for tHandle in handleList:
tItem = self.getItem(tHandle)
if tItem is None:
continue
if tItem.itemType == nwItemType.FILE:
fileList.append(tHandle)
else:
pass
mergeText = ""
for tHandle in fileList:
pass
return True
##
# Set Functions
##
@@ -485,9 +452,6 @@ class NWProject():
self.setProjectChanged(True)
return True
def getSessionWordCount(self):
return self.currWCount - self.lastWCount
def setStatusColours(self, newCols):
replaceMap = self.statusItems.setNewEntries(newCols)
if self.projTree is not None:
@@ -530,6 +494,9 @@ class NWProject():
logger.error("No tree item with handle %s" % str(tHandle))
return None
def getSessionWordCount(self):
return self.currWCount - self.lastWCount
def getRootItem(self, tHandle):
"""Iterate upwards in the tree until we find the item with
parent None, the root item. We do this with a for loop with a
@@ -538,10 +505,13 @@ class NWProject():
tItem = self.getItem(tHandle)
if tItem is not None:
for i in range(200):
tHandle = tItem.parHandle
tItem = self.getItem(tHandle)
if tItem is None:
if tItem.parHandle is None:
return tHandle
else:
tHandle = tItem.parHandle
tItem = self.getItem(tHandle)
if tItem is None:
return tHandle
return None
def getProjectItems(self):