Cleanup (#820)
* Update instructions and readmes * Cleanup in base files * Cleanup in core files * Cleanup in gui files * Cleanup in dialog files * Cleanup in tools files * Cleanup in test files
This commit is contained in:
committed by
GitHub
parent
1881b3d32c
commit
6d7ca2bb86
+2
-2
@@ -82,7 +82,7 @@ class NWDoc():
|
||||
self._docMeta = {}
|
||||
if os.path.isfile(docPath):
|
||||
try:
|
||||
with open(docPath, mode="r", encoding="utf8") as inFile:
|
||||
with open(docPath, mode="r", encoding="utf-8") as inFile:
|
||||
|
||||
# Check the first <= 10 lines for metadata
|
||||
for i in range(10):
|
||||
@@ -136,7 +136,7 @@ class NWDoc():
|
||||
)
|
||||
|
||||
try:
|
||||
with open(docTemp, mode="w", encoding="utf8") as outFile:
|
||||
with open(docTemp, mode="w", encoding="utf-8") as outFile:
|
||||
outFile.write(docMeta)
|
||||
outFile.write(docText)
|
||||
except Exception as e:
|
||||
|
||||
+15
-15
@@ -144,13 +144,13 @@ class NWIndex():
|
||||
def loadIndex(self):
|
||||
"""Load index from last session from the project meta folder.
|
||||
"""
|
||||
theData = {}
|
||||
theData = {}
|
||||
indexFile = os.path.join(self.theProject.projMeta, nwFiles.INDEX_FILE)
|
||||
|
||||
if os.path.isfile(indexFile):
|
||||
logger.debug("Loading index file")
|
||||
try:
|
||||
with open(indexFile, mode="r", encoding="utf8") as inFile:
|
||||
with open(indexFile, mode="r", encoding="utf-8") as inFile:
|
||||
theData = json.load(inFile)
|
||||
except Exception:
|
||||
logger.error("Failed to load index file")
|
||||
@@ -158,10 +158,10 @@ class NWIndex():
|
||||
self.indexBroken = True
|
||||
return False
|
||||
|
||||
self._tagIndex = theData.get("tagIndex", {})
|
||||
self._refIndex = theData.get("refIndex", {})
|
||||
self._tagIndex = theData.get("tagIndex", {})
|
||||
self._refIndex = theData.get("refIndex", {})
|
||||
self._novelIndex = theData.get("novelIndex", {})
|
||||
self._noteIndex = theData.get("noteIndex", {})
|
||||
self._noteIndex = theData.get("noteIndex", {})
|
||||
self._textCounts = theData.get("textCounts", {})
|
||||
|
||||
nowTime = round(time())
|
||||
@@ -181,12 +181,12 @@ class NWIndex():
|
||||
indexFile = os.path.join(self.theProject.projMeta, nwFiles.INDEX_FILE)
|
||||
|
||||
try:
|
||||
with open(indexFile, mode="w+", encoding="utf8") as outFile:
|
||||
with open(indexFile, mode="w+", encoding="utf-8") as outFile:
|
||||
json.dump({
|
||||
"tagIndex": self._tagIndex,
|
||||
"refIndex": self._refIndex,
|
||||
"tagIndex": self._tagIndex,
|
||||
"refIndex": self._refIndex,
|
||||
"novelIndex": self._novelIndex,
|
||||
"noteIndex": self._noteIndex,
|
||||
"noteIndex": self._noteIndex,
|
||||
"textCounts": self._textCounts,
|
||||
}, outFile, indent=2)
|
||||
except Exception:
|
||||
@@ -292,12 +292,12 @@ class NWIndex():
|
||||
for aTag in clearTags:
|
||||
self._tagIndex.pop(aTag)
|
||||
|
||||
nLine = 0
|
||||
nLine = 0
|
||||
nTitle = 0
|
||||
theLines = theText.splitlines()
|
||||
for aLine in theLines:
|
||||
nLine += 1
|
||||
nChar = len(aLine.strip())
|
||||
nChar = len(aLine.strip())
|
||||
if nChar == 0:
|
||||
continue
|
||||
|
||||
@@ -352,16 +352,16 @@ class NWIndex():
|
||||
"""
|
||||
if aLine.startswith("# "):
|
||||
hDepth = "H1"
|
||||
hText = aLine[2:].strip()
|
||||
hText = aLine[2:].strip()
|
||||
elif aLine.startswith("## "):
|
||||
hDepth = "H2"
|
||||
hText = aLine[3:].strip()
|
||||
hText = aLine[3:].strip()
|
||||
elif aLine.startswith("### "):
|
||||
hDepth = "H3"
|
||||
hText = aLine[4:].strip()
|
||||
hText = aLine[4:].strip()
|
||||
elif aLine.startswith("#### "):
|
||||
hDepth = "H4"
|
||||
hText = aLine[5:].strip()
|
||||
hText = aLine[5:].strip()
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
+3
-3
@@ -125,12 +125,12 @@ class OptionState():
|
||||
return False
|
||||
|
||||
stateFile = os.path.join(self.theProject.projMeta, nwFiles.OPTS_FILE)
|
||||
theState = {}
|
||||
theState = {}
|
||||
|
||||
if os.path.isfile(stateFile):
|
||||
logger.debug("Loading GUI options file")
|
||||
try:
|
||||
with open(stateFile, mode="r", encoding="utf8") as inFile:
|
||||
with open(stateFile, mode="r", encoding="utf-8") as inFile:
|
||||
theState = json.load(inFile)
|
||||
except Exception:
|
||||
logger.error("Failed to load GUI options file")
|
||||
@@ -157,7 +157,7 @@ class OptionState():
|
||||
logger.debug("Saving GUI options file")
|
||||
|
||||
try:
|
||||
with open(stateFile, mode="w+", encoding="utf8") as outFile:
|
||||
with open(stateFile, mode="w+", encoding="utf-8") as outFile:
|
||||
json.dump(self.theState, outFile, indent=2)
|
||||
except Exception:
|
||||
logger.error("Failed to save GUI options file")
|
||||
|
||||
+17
-18
@@ -355,7 +355,7 @@ class NWProject():
|
||||
|
||||
def openProject(self, fileName, overrideLock=False):
|
||||
"""Open the project file provided, or if doesn't exist, assume
|
||||
it is a folder, and look for the file within it. If successful,
|
||||
it is a folder and look for the file within it. If successful,
|
||||
parse the XML of the file and populate the project variables and
|
||||
build the tree of project items.
|
||||
"""
|
||||
@@ -483,10 +483,11 @@ class NWProject():
|
||||
msgYes = self.theParent.askQuestion(
|
||||
self.tr("Version Conflict"),
|
||||
self.tr(
|
||||
"This project was saved by a newer version of novelWriter, version "
|
||||
"{0}. This is version {1}. If you continue to open the project, "
|
||||
"some attributes and settings may not be preserved, but the "
|
||||
"overall project should be fine. Continue opening the project?"
|
||||
"This project was saved by a newer version of "
|
||||
"novelWriter, version {0}. This is version {1}. If you "
|
||||
"continue to open the project, some attributes and "
|
||||
"settings may not be preserved, but the overall project "
|
||||
"should be fine. Continue opening the project?"
|
||||
).format(appVersion, nw.__version__)
|
||||
)
|
||||
if not msgYes:
|
||||
@@ -1219,7 +1220,7 @@ class NWProject():
|
||||
loadFile = chkFile2
|
||||
|
||||
try:
|
||||
with open(loadFile, mode="r", encoding="utf8") as inFile:
|
||||
with open(loadFile, mode="r", encoding="utf-8") as inFile:
|
||||
self.langData = json.load(inFile)
|
||||
logger.debug("Loaded project language file: %s", os.path.basename(loadFile))
|
||||
|
||||
@@ -1242,7 +1243,7 @@ class NWProject():
|
||||
|
||||
theLines = []
|
||||
try:
|
||||
with open(lockFile, mode="r", encoding="utf8") as inFile:
|
||||
with open(lockFile, mode="r", encoding="utf-8") as inFile:
|
||||
theData = inFile.read()
|
||||
theLines = theData.splitlines()
|
||||
if len(theLines) != 4:
|
||||
@@ -1263,7 +1264,7 @@ class NWProject():
|
||||
|
||||
lockFile = os.path.join(self.projPath, nwFiles.PROJ_LOCK)
|
||||
try:
|
||||
with open(lockFile, mode="w+", encoding="utf8") as outFile:
|
||||
with open(lockFile, mode="w+", encoding="utf-8") as outFile:
|
||||
outFile.write("%s\n" % self.mainConf.hostName)
|
||||
outFile.write("%s\n" % self.mainConf.osType)
|
||||
outFile.write("%s\n" % self.mainConf.kernelVer)
|
||||
@@ -1442,7 +1443,7 @@ class NWProject():
|
||||
return False
|
||||
|
||||
try:
|
||||
with open(sessionFile, mode="a+", encoding="utf8") as outFile:
|
||||
with open(sessionFile, mode="a+", encoding="utf-8") as outFile:
|
||||
if not isFile:
|
||||
# It's a new file, so add a header
|
||||
if self.lastWCount > 0:
|
||||
@@ -1481,7 +1482,6 @@ class NWProject():
|
||||
logger.info("Old data folder %s found", theFolder)
|
||||
|
||||
# Move Documents to Content
|
||||
# =========================
|
||||
for dataItem in os.listdir(theData):
|
||||
theFile = os.path.join(theData, dataItem)
|
||||
if not os.path.isfile(theFile):
|
||||
@@ -1517,7 +1517,6 @@ class NWProject():
|
||||
errList.append(theErr)
|
||||
|
||||
# Remove Data Folder
|
||||
# ==================
|
||||
try:
|
||||
os.rmdir(theData)
|
||||
logger.info("Deleted folder: %s", theFolder)
|
||||
@@ -1563,13 +1562,13 @@ class NWProject():
|
||||
os.path.join(self.projCache, "nwProject.nwx.7"),
|
||||
os.path.join(self.projCache, "nwProject.nwx.8"),
|
||||
os.path.join(self.projCache, "nwProject.nwx.9"),
|
||||
os.path.join(self.projMeta, "mainOptions.json"),
|
||||
os.path.join(self.projMeta, "exportOptions.json"),
|
||||
os.path.join(self.projMeta, "outlineOptions.json"),
|
||||
os.path.join(self.projMeta, "timelineOptions.json"),
|
||||
os.path.join(self.projMeta, "docMergeOptions.json"),
|
||||
os.path.join(self.projMeta, "sessionLogOptions.json"),
|
||||
os.path.join(self.projPath, "ToC.json"),
|
||||
os.path.join(self.projMeta, "mainOptions.json"),
|
||||
os.path.join(self.projMeta, "exportOptions.json"),
|
||||
os.path.join(self.projMeta, "outlineOptions.json"),
|
||||
os.path.join(self.projMeta, "timelineOptions.json"),
|
||||
os.path.join(self.projMeta, "docMergeOptions.json"),
|
||||
os.path.join(self.projMeta, "sessionLogOptions.json"),
|
||||
os.path.join(self.projPath, "ToC.json"),
|
||||
]
|
||||
|
||||
for rmFile in rmList:
|
||||
|
||||
@@ -235,8 +235,7 @@ class FakeEnchant:
|
||||
class NWSpellSimple(NWSpellCheck):
|
||||
"""Internal spell check tool that uses standard Python packages with
|
||||
no other external dependencies. This is the fallback spell checker
|
||||
when no other is available. This method is fairly slow compared to
|
||||
other implementations.
|
||||
when no other is available. This method is slower than enchant.
|
||||
"""
|
||||
theWords = set()
|
||||
|
||||
|
||||
+12
-10
@@ -35,12 +35,14 @@ logger = logging.getLogger(__name__)
|
||||
class NWStatus():
|
||||
|
||||
def __init__(self):
|
||||
self._theLabels = []
|
||||
|
||||
self._theLabels = []
|
||||
self._theColours = []
|
||||
self._theCounts = []
|
||||
self._theMap = {}
|
||||
self._theLength = 0
|
||||
self._theIndex = 0
|
||||
self._theCounts = []
|
||||
self._theMap = {}
|
||||
self._theLength = 0
|
||||
self._theIndex = 0
|
||||
|
||||
return
|
||||
|
||||
def addEntry(self, theLabel, theColours):
|
||||
@@ -87,12 +89,12 @@ class NWStatus():
|
||||
replaceMap = {}
|
||||
|
||||
if newList is not None:
|
||||
self._theLabels = []
|
||||
self._theLabels = []
|
||||
self._theColours = []
|
||||
self._theCounts = []
|
||||
self._theMap = {}
|
||||
self._theLength = 0
|
||||
self._theIndex = 0
|
||||
self._theCounts = []
|
||||
self._theMap = {}
|
||||
self._theLength = 0
|
||||
self._theIndex = 0
|
||||
|
||||
for nName, nR, nG, nB, oName in newList:
|
||||
self.addEntry(nName, (nR, nG, nB))
|
||||
|
||||
+4
-4
@@ -40,9 +40,9 @@ class ToHtml(Tokenizer):
|
||||
def __init__(self, theProject):
|
||||
Tokenizer.__init__(self, theProject)
|
||||
|
||||
self.genMode = self.M_EXPORT
|
||||
self.genMode = self.M_EXPORT
|
||||
self.cssStyles = True
|
||||
self.fullHTML = []
|
||||
self.fullHTML = []
|
||||
|
||||
# Internals
|
||||
self._trMap = {}
|
||||
@@ -59,7 +59,7 @@ class ToHtml(Tokenizer):
|
||||
need to make a few changes to formatting, which is managed by
|
||||
these flags.
|
||||
"""
|
||||
self.genMode = self.M_PREVIEW
|
||||
self.genMode = self.M_PREVIEW
|
||||
self.doKeywords = True
|
||||
self.doComments = doComments
|
||||
self.doSynopsis = doSynopsis
|
||||
@@ -268,7 +268,7 @@ class ToHtml(Tokenizer):
|
||||
def saveHTML5(self, savePath):
|
||||
"""Save the data to an .html file.
|
||||
"""
|
||||
with open(savePath, mode="w", encoding="utf8") as outFile:
|
||||
with open(savePath, mode="w", encoding="utf-8") as outFile:
|
||||
theStyle = self.getStyleSheet()
|
||||
theStyle.append("article {width: 800px; margin: 40px auto;}")
|
||||
bodyText = "".join(self.fullHTML)
|
||||
|
||||
+19
-19
@@ -24,8 +24,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
import nw
|
||||
import logging
|
||||
import re
|
||||
import logging
|
||||
|
||||
from operator import itemgetter
|
||||
from functools import partial
|
||||
@@ -43,12 +43,12 @@ logger = logging.getLogger(__name__)
|
||||
class Tokenizer():
|
||||
|
||||
# In-Text Format
|
||||
FMT_B_B = 1 # Begin bold
|
||||
FMT_B_E = 2 # End bold
|
||||
FMT_I_B = 3 # Begin italics
|
||||
FMT_I_E = 4 # End italics
|
||||
FMT_D_B = 5 # Begin strikeout
|
||||
FMT_D_E = 6 # End strikeout
|
||||
FMT_B_B = 1 # Begin bold
|
||||
FMT_B_E = 2 # End bold
|
||||
FMT_I_B = 3 # Begin italics
|
||||
FMT_I_E = 4 # End italics
|
||||
FMT_D_B = 5 # Begin strikeout
|
||||
FMT_D_E = 6 # End strikeout
|
||||
|
||||
# Block Type
|
||||
T_EMPTY = 1 # Empty line (new paragraph)
|
||||
@@ -86,11 +86,11 @@ class Tokenizer():
|
||||
self.mainConf = nw.CONFIG
|
||||
|
||||
# Data Variables
|
||||
self.theText = "" # The raw text to be tokenized
|
||||
self.theHandle = None # The handle associated with the text
|
||||
self.theItem = None # The NWItem associated with the handle
|
||||
self.theTokens = [] # The list of the processed tokens
|
||||
self.theResult = "" # The result of the last document
|
||||
self.theText = "" # The raw text to be tokenized
|
||||
self.theHandle = None # The handle associated with the text
|
||||
self.theItem = None # The NWItem associated with the handle
|
||||
self.theTokens = [] # The list of the processed tokens
|
||||
self.theResult = "" # The result of the last document
|
||||
|
||||
self.keepMarkdown = False # Whether to keep the markdown text
|
||||
self.theMarkdown = [] # The result novelWriter markdown of all documents
|
||||
@@ -117,11 +117,11 @@ class Tokenizer():
|
||||
self.marginMeta = (0.000, 0.584)
|
||||
|
||||
# Title Formats
|
||||
self.fmtTitle = "%title%" # Formatting for titles
|
||||
self.fmtChapter = "%title%" # Formatting for numbered chapters
|
||||
self.fmtUnNum = "%title%" # Formatting for unnumbered chapters
|
||||
self.fmtScene = "%title%" # Formatting for scenes
|
||||
self.fmtSection = "%title%" # Formatting for sections
|
||||
self.fmtTitle = "%title%" # Formatting for titles
|
||||
self.fmtChapter = "%title%" # Formatting for numbered chapters
|
||||
self.fmtUnNum = "%title%" # Formatting for unnumbered chapters
|
||||
self.fmtScene = "%title%" # Formatting for scenes
|
||||
self.fmtSection = "%title%" # Formatting for sections
|
||||
|
||||
self.hideScene = False # Do not include scene headers
|
||||
self.hideSection = False # Do not include section headers
|
||||
@@ -320,7 +320,7 @@ class Tokenizer():
|
||||
return True
|
||||
|
||||
def doPreProcessing(self):
|
||||
"""Reun trough the various replace doctionaries.
|
||||
"""Run trough the various replace doctionaries.
|
||||
"""
|
||||
# Process the user's auto-replace dictionary
|
||||
if len(self.theProject.autoReplace) > 0:
|
||||
@@ -701,7 +701,7 @@ class Tokenizer():
|
||||
def saveRawMarkdown(self, savePath):
|
||||
"""Save the data to a plain text file.
|
||||
"""
|
||||
with open(savePath, mode="w", encoding="utf8") as outFile:
|
||||
with open(savePath, mode="w", encoding="utf-8") as outFile:
|
||||
for nwdPage in self.theMarkdown:
|
||||
outFile.write(nwdPage)
|
||||
return
|
||||
|
||||
+14
-8
@@ -72,16 +72,22 @@ class ToMarkdown(Tokenizer):
|
||||
if self.genMode == self.M_STD:
|
||||
# Standard
|
||||
mdTags = {
|
||||
self.FMT_B_B: "**", self.FMT_B_E: "**",
|
||||
self.FMT_I_B: "_", self.FMT_I_E: "_",
|
||||
self.FMT_D_B: "", self.FMT_D_E: "",
|
||||
self.FMT_B_B: "**",
|
||||
self.FMT_B_E: "**",
|
||||
self.FMT_I_B: "_",
|
||||
self.FMT_I_E: "_",
|
||||
self.FMT_D_B: "",
|
||||
self.FMT_D_E: "",
|
||||
}
|
||||
else:
|
||||
# GitHub
|
||||
mdTags = {
|
||||
self.FMT_B_B: "**", self.FMT_B_E: "**",
|
||||
self.FMT_I_B: "_", self.FMT_I_E: "_",
|
||||
self.FMT_D_B: "~~", self.FMT_D_E: "~~",
|
||||
self.FMT_B_B: "**",
|
||||
self.FMT_B_E: "**",
|
||||
self.FMT_I_B: "_",
|
||||
self.FMT_I_E: "_",
|
||||
self.FMT_D_B: "~~",
|
||||
self.FMT_D_E: "~~",
|
||||
}
|
||||
|
||||
self.theResult = ""
|
||||
@@ -149,7 +155,7 @@ class ToMarkdown(Tokenizer):
|
||||
def saveMarkdown(self, savePath):
|
||||
"""Save the data to a plain text file.
|
||||
"""
|
||||
with open(savePath, mode="w", encoding="utf8") as outFile:
|
||||
with open(savePath, mode="w", encoding="utf-8") as outFile:
|
||||
theText = "".join(self.fullMD)
|
||||
outFile.write(theText)
|
||||
|
||||
@@ -173,7 +179,7 @@ class ToMarkdown(Tokenizer):
|
||||
def _formatKeywords(self, tText, tStyle):
|
||||
"""Apply Markdown formatting to keywords.
|
||||
"""
|
||||
isValid, theBits, thePos = self.theParent.theIndex.scanThis("@"+tText)
|
||||
isValid, theBits, _ = self.theParent.theIndex.scanThis("@"+tText)
|
||||
if not isValid or not theBits:
|
||||
return ""
|
||||
|
||||
|
||||
+3
-3
@@ -24,11 +24,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
import nw
|
||||
import logging
|
||||
import os
|
||||
import logging
|
||||
|
||||
from lxml import etree
|
||||
from time import time
|
||||
from lxml import etree
|
||||
from hashlib import sha256
|
||||
|
||||
from nw.enum import nwItemType, nwItemClass, nwItemLayout
|
||||
@@ -193,7 +193,7 @@ class NWTree():
|
||||
try:
|
||||
# Dump the text
|
||||
tocText = os.path.join(self.theProject.projPath, nwFiles.TOC_TXT)
|
||||
with open(tocText, mode="w", encoding="utf8") as outFile:
|
||||
with open(tocText, mode="w", encoding="utf-8") as outFile:
|
||||
outFile.write("\n")
|
||||
outFile.write("Table of Contents\n")
|
||||
outFile.write("=================\n")
|
||||
|
||||
Reference in New Issue
Block a user