Added a function to clean out old project files no longer needed
This commit is contained in:
@@ -22,6 +22,7 @@ from time import time
|
|||||||
|
|
||||||
from nw.project.status import NWStatus
|
from nw.project.status import NWStatus
|
||||||
from nw.project.item import NWItem
|
from nw.project.item import NWItem
|
||||||
|
from nw.tools import projectMaintenance
|
||||||
from nw.common import checkString, checkBool, checkInt
|
from nw.common import checkString, checkBool, checkInt
|
||||||
from nw.constants import (
|
from nw.constants import (
|
||||||
nwFiles, nwConst, nwItemType, nwItemClass, nwItemLayout, nwAlert
|
nwFiles, nwConst, nwItemType, nwItemClass, nwItemLayout, nwAlert
|
||||||
@@ -200,6 +201,11 @@ class NWProject():
|
|||||||
if not self._checkFolder(self.projMeta):
|
if not self._checkFolder(self.projMeta):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
projectMaintenance(self)
|
||||||
|
except Exception as E:
|
||||||
|
logger.error(str(E))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
nwXML = etree.parse(fileName)
|
nwXML = etree.parse(fileName)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from nw.tools.analyse import TextAnalysis
|
from nw.tools.analyse import TextAnalysis
|
||||||
|
from nw.tools.legacy import projectMaintenance
|
||||||
from nw.tools.optlaststate import OptLastState
|
from nw.tools.optlaststate import OptLastState
|
||||||
from nw.tools.spellcheck import NWSpellCheck
|
from nw.tools.spellcheck import NWSpellCheck
|
||||||
from nw.tools.spellenchant import NWSpellEnchant
|
from nw.tools.spellenchant import NWSpellEnchant
|
||||||
@@ -10,6 +11,7 @@ from nw.tools.wordcount import countWords
|
|||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"TextAnalysis",
|
"TextAnalysis",
|
||||||
|
"projectMaintenance",
|
||||||
"OptLastState",
|
"OptLastState",
|
||||||
"NWSpellCheck",
|
"NWSpellCheck",
|
||||||
"NWSpellEnchant",
|
"NWSpellEnchant",
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""novelWriter Legacy Tools
|
||||||
|
|
||||||
|
novelWriter – Legacy Tools
|
||||||
|
============================
|
||||||
|
Various functions to handle old projects
|
||||||
|
|
||||||
|
File History:
|
||||||
|
Created: 2020-02-13 [0.4.3]
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import nw
|
||||||
|
|
||||||
|
from os import path, unlink, rmdir
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
def projectMaintenance(theProject):
|
||||||
|
"""Wrapper class for handling various tasks related to managing old
|
||||||
|
projects with content from older versions of novelWriter.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Remove no longer used project cache folder
|
||||||
|
if path.isdir(theProject.projPath):
|
||||||
|
cacheDir = path.join(theProject.projPath, "cache")
|
||||||
|
if path.isdir(cacheDir):
|
||||||
|
logger.info("Deprecated cache folder found")
|
||||||
|
rmList = []
|
||||||
|
for i in range(10):
|
||||||
|
rmList.append(path.join(cacheDir, "nwProject.nwx.%d" % i))
|
||||||
|
rmList.append(path.join(cacheDir, "projCount.txt"))
|
||||||
|
for rmFile in rmList:
|
||||||
|
if path.isfile(rmFile):
|
||||||
|
logger.info("Deleting: %s" % rmFile)
|
||||||
|
try:
|
||||||
|
unlink(rmFile)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(str(e))
|
||||||
|
logger.info("Deleting: %s" % cacheDir)
|
||||||
|
try:
|
||||||
|
rmdir(cacheDir)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(str(e))
|
||||||
|
|
||||||
|
return
|
||||||
Reference in New Issue
Block a user