Further PEP8 compliance changes
This commit is contained in:
@@ -13,8 +13,8 @@
|
||||
import logging
|
||||
import nw
|
||||
|
||||
from os import path, mkdir, listdir
|
||||
from shutil import make_archive
|
||||
from os import path, mkdir, listdir
|
||||
from shutil import make_archive
|
||||
from datetime import datetime
|
||||
|
||||
from nw.enum import nwAlert
|
||||
|
||||
@@ -103,9 +103,12 @@ class NWDoc():
|
||||
docTemp = path.join(dataPath,docFile[:-3]+"tmp")
|
||||
docBack = path.join(dataPath,docFile[:-3]+"bak")
|
||||
|
||||
if path.isfile(docTemp): unlink(docTemp)
|
||||
if path.isfile(docBack): rename(docBack,docTemp)
|
||||
if path.isfile(docPath): rename(docPath,docBack)
|
||||
if path.isfile(docTemp):
|
||||
unlink(docTemp)
|
||||
if path.isfile(docBack):
|
||||
rename(docBack,docTemp)
|
||||
if path.isfile(docPath):
|
||||
rename(docPath,docBack)
|
||||
|
||||
try:
|
||||
with open(docPath,mode="w",encoding="utf8") as outFile:
|
||||
|
||||
+7
-9
@@ -17,9 +17,9 @@ import nw
|
||||
from os import path
|
||||
|
||||
from nw.project.document import NWDoc
|
||||
from nw.enum import nwItemType, nwItemClass, nwItemLayout
|
||||
from nw.constants import nwFiles, nwKeyWords
|
||||
from nw.enum import nwAlert
|
||||
from nw.enum import nwItemType, nwItemClass, nwItemLayout
|
||||
from nw.constants import nwFiles, nwKeyWords
|
||||
from nw.enum import nwAlert
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -62,7 +62,7 @@ class NWIndex():
|
||||
self.noteIndex = {}
|
||||
|
||||
# Lists
|
||||
self.novelList = []
|
||||
self.novelList = []
|
||||
|
||||
return
|
||||
|
||||
@@ -101,7 +101,7 @@ class NWIndex():
|
||||
"""Load index from last session from the project meta folder.
|
||||
"""
|
||||
|
||||
theData = {}
|
||||
theData = {}
|
||||
indexFile = path.join(self.theProject.projMeta, nwFiles.INDEX_FILE)
|
||||
if path.isfile(indexFile):
|
||||
logger.debug("Loading index file")
|
||||
@@ -213,11 +213,11 @@ class NWIndex():
|
||||
# Check file type, and reset its old index
|
||||
if itemClass == nwItemClass.NOVEL:
|
||||
self.novelIndex[tHandle] = []
|
||||
self.refIndex[tHandle] = []
|
||||
self.refIndex[tHandle] = []
|
||||
isNovel = True
|
||||
else:
|
||||
self.noteIndex[tHandle] = []
|
||||
self.refIndex[tHandle] = []
|
||||
self.refIndex[tHandle] = []
|
||||
isNovel = False
|
||||
|
||||
# Also clear references to file in tag index
|
||||
@@ -390,7 +390,6 @@ class NWIndex():
|
||||
def buildNovelList(self):
|
||||
"""Build a list of the content of the novel.
|
||||
"""
|
||||
|
||||
self.novelList = []
|
||||
self.novelOrder = []
|
||||
for tHandle in self.theProject.treeOrder:
|
||||
@@ -399,7 +398,6 @@ class NWIndex():
|
||||
for tEntry in self.novelIndex[tHandle]:
|
||||
self.novelList.append(tEntry)
|
||||
self.novelOrder.append("%s:%d" % (tHandle,tEntry[0]))
|
||||
|
||||
return True
|
||||
|
||||
def buildReferenceList(self, tHandle):
|
||||
|
||||
+18
-18
@@ -13,11 +13,11 @@
|
||||
import logging
|
||||
import nw
|
||||
|
||||
from os import path, mkdir
|
||||
from lxml import etree
|
||||
from datetime import datetime
|
||||
from os import path, mkdir
|
||||
from lxml import etree
|
||||
from datetime import datetime
|
||||
|
||||
from nw.enum import nwItemType, nwItemClass, nwItemLayout
|
||||
from nw.enum import nwItemType, nwItemClass, nwItemLayout
|
||||
from nw.common import checkInt
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -28,23 +28,23 @@ class NWItem():
|
||||
|
||||
def __init__(self, theProject):
|
||||
|
||||
self.theProject = theProject
|
||||
self.theProject = theProject
|
||||
|
||||
self.itemName = ""
|
||||
self.itemHandle = None
|
||||
self.parHandle = None
|
||||
self.itemOrder = None
|
||||
self.itemType = nwItemType.NO_TYPE
|
||||
self.itemClass = nwItemClass.NO_CLASS
|
||||
self.itemLayout = nwItemLayout.NO_LAYOUT
|
||||
self.itemStatus = None
|
||||
self.isExpanded = False
|
||||
self.itemName = ""
|
||||
self.itemHandle = None
|
||||
self.parHandle = None
|
||||
self.itemOrder = None
|
||||
self.itemType = nwItemType.NO_TYPE
|
||||
self.itemClass = nwItemClass.NO_CLASS
|
||||
self.itemLayout = nwItemLayout.NO_LAYOUT
|
||||
self.itemStatus = None
|
||||
self.isExpanded = False
|
||||
|
||||
# Document Meta Data
|
||||
self.charCount = 0
|
||||
self.wordCount = 0
|
||||
self.paraCount = 0
|
||||
self.cursorPos = 0
|
||||
self.charCount = 0
|
||||
self.wordCount = 0
|
||||
self.paraCount = 0
|
||||
self.cursorPos = 0
|
||||
|
||||
return
|
||||
|
||||
|
||||
+40
-38
@@ -13,18 +13,18 @@
|
||||
import logging
|
||||
import nw
|
||||
|
||||
from os import path, mkdir, listdir
|
||||
from shutil import copyfile
|
||||
from lxml import etree
|
||||
from hashlib import sha256
|
||||
from os import path, mkdir, listdir
|
||||
from shutil import copyfile
|
||||
from lxml import etree
|
||||
from hashlib import sha256
|
||||
from datetime import datetime
|
||||
from time import time
|
||||
from time import time
|
||||
|
||||
from nw.project.item import NWItem
|
||||
from nw.project.item import NWItem
|
||||
from nw.project.status import NWStatus
|
||||
from nw.enum import nwItemType, nwItemClass, nwItemLayout, nwAlert
|
||||
from nw.common import checkString, checkBool, checkInt
|
||||
from nw.constants import nwFiles, nwConst
|
||||
from nw.enum import nwItemType, nwItemClass, nwItemLayout, nwAlert
|
||||
from nw.common import checkString, checkBool, checkInt
|
||||
from nw.constants import nwFiles, nwConst
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -40,18 +40,18 @@ class NWProject():
|
||||
self.projAltered = None # The project has been altered this session
|
||||
|
||||
# Debug
|
||||
self.handleSeed = None
|
||||
self.handleSeed = None
|
||||
|
||||
# Class Settings
|
||||
self.projTree = None # Holds all the items of the project
|
||||
self.treeOrder = None # The order of the tree items on the tree view
|
||||
self.treeRoots = None # The root items of the tree
|
||||
self.trashRoot = None # The handle of the trash root folder
|
||||
self.projPath = None # The full path to where the currently open project is saved
|
||||
self.projMeta = None # The full path to the project's meta data folder
|
||||
self.projCache = None # The full path to the project's cache folder
|
||||
self.projDict = None # The spell check dictionary
|
||||
self.projFile = None # The file name of the project main xml file
|
||||
self.projTree = None # Holds all the items of the project
|
||||
self.treeOrder = None # The order of the tree items on the tree view
|
||||
self.treeRoots = None # The root items of the tree
|
||||
self.trashRoot = None # The handle of the trash root folder
|
||||
self.projPath = None # The full path to where the currently open project is saved
|
||||
self.projMeta = None # The full path to the project's meta data folder
|
||||
self.projCache = None # The full path to the project's cache folder
|
||||
self.projDict = None # The spell check dictionary
|
||||
self.projFile = None # The file name of the project main xml file
|
||||
|
||||
# Project Meta
|
||||
self.projName = None
|
||||
@@ -194,8 +194,10 @@ class NWProject():
|
||||
self.projCache = path.join(self.projPath,"cache")
|
||||
self.projDict = path.join(self.projMeta, nwFiles.PROJ_DICT)
|
||||
|
||||
if not self._checkFolder(self.projMeta): return
|
||||
if not self._checkFolder(self.projCache): return
|
||||
if not self._checkFolder(self.projMeta):
|
||||
return
|
||||
if not self._checkFolder(self.projCache):
|
||||
return
|
||||
|
||||
try:
|
||||
nwXML = etree.parse(fileName)
|
||||
@@ -313,19 +315,19 @@ class NWProject():
|
||||
})
|
||||
|
||||
# Save Project Meta
|
||||
xProject = etree.SubElement(nwXML,"project")
|
||||
self._saveProjectValue(xProject,"name", self.projName, True)
|
||||
self._saveProjectValue(xProject,"title", self.bookTitle, True)
|
||||
self._saveProjectValue(xProject,"author",self.bookAuthors)
|
||||
self._saveProjectValue(xProject,"backup",self.doBackup)
|
||||
xProject = etree.SubElement(nwXML, "project")
|
||||
self._saveProjectValue(xProject, "name", self.projName, True)
|
||||
self._saveProjectValue(xProject, "title", self.bookTitle, True)
|
||||
self._saveProjectValue(xProject, "author", self.bookAuthors)
|
||||
self._saveProjectValue(xProject, "backup", self.doBackup)
|
||||
|
||||
# Save Project Settings
|
||||
xSettings = etree.SubElement(nwXML,"settings")
|
||||
self._saveProjectValue(xSettings,"spellCheck", self.spellCheck)
|
||||
self._saveProjectValue(xSettings,"lastEdited", self.lastEdited)
|
||||
self._saveProjectValue(xSettings,"lastViewed", self.lastViewed)
|
||||
self._saveProjectValue(xSettings,"lastWordCount",self.currWCount)
|
||||
xAutoRep = etree.SubElement(xSettings,"autoReplace")
|
||||
xSettings = etree.SubElement(nwXML, "settings")
|
||||
self._saveProjectValue(xSettings, "spellCheck", self.spellCheck)
|
||||
self._saveProjectValue(xSettings, "lastEdited", self.lastEdited)
|
||||
self._saveProjectValue(xSettings, "lastViewed", self.lastViewed)
|
||||
self._saveProjectValue(xSettings, "lastWordCount", self.currWCount)
|
||||
xAutoRep = etree.SubElement(xSettings, "autoReplace")
|
||||
for aKey, aValue in self.autoReplace.items():
|
||||
if len(aKey) > 0:
|
||||
self._saveProjectValue(xAutoRep,aKey,aValue)
|
||||
@@ -337,7 +339,7 @@ class NWProject():
|
||||
|
||||
# Save Tree Content
|
||||
logger.debug("Writing project content")
|
||||
xContent = etree.SubElement(nwXML,"content",attrib={"count":str(len(self.treeOrder))})
|
||||
xContent = etree.SubElement(nwXML, "content", attrib={"count":str(len(self.treeOrder))})
|
||||
for tHandle in self.treeOrder:
|
||||
self.projTree[tHandle].packXML(xContent)
|
||||
|
||||
@@ -411,8 +413,8 @@ class NWProject():
|
||||
return False
|
||||
if self.projName == "":
|
||||
self.theParent.makeAlert((
|
||||
"You must set a valid project name in project settings to use "
|
||||
"the automatic project backup feature."
|
||||
"You must set a valid project name in project settings to "
|
||||
"use the automatic project backup feature."
|
||||
), nwAlert.ERROR)
|
||||
return False
|
||||
self.doBackup = True
|
||||
@@ -699,7 +701,7 @@ class NWProject():
|
||||
|
||||
sessionFile = path.join(self.projMeta, nwFiles.SESS_INFO)
|
||||
|
||||
with open(sessionFile,mode="a+",encoding="utf8") as outFile:
|
||||
with open(sessionFile, mode="a+", encoding="utf8") as outFile:
|
||||
print((
|
||||
"Start: {opened:s} "
|
||||
"End: {closed:s} "
|
||||
@@ -750,8 +752,8 @@ class NWProject():
|
||||
|
||||
try:
|
||||
copyfile(
|
||||
path.join(self.projPath,self.projFile),
|
||||
path.join(self.projCache,projBackup)
|
||||
path.join(self.projPath, self.projFile),
|
||||
path.join(self.projCache, projBackup)
|
||||
)
|
||||
except:
|
||||
logger.error("Failed to write to file %s" % projBackup)
|
||||
|
||||
@@ -15,7 +15,7 @@ import nw
|
||||
|
||||
from lxml import etree
|
||||
|
||||
from nw.enum import nwItemClass
|
||||
from nw.enum import nwItemClass
|
||||
from nw.common import checkInt
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
Reference in New Issue
Block a user