Drop the whole firstTitle index again

This commit is contained in:
Veronica K. B. Olsen
2021-02-01 23:20:07 +01:00
parent cada78ca4d
commit 3baeef4f44
4 changed files with 5 additions and 153 deletions
-33
View File
@@ -59,7 +59,6 @@ class NWIndex():
self._novelIndex = {}
self._noteIndex = {}
self._textCounts = {}
self._firstTitle = {}
# TimeStamps
self._timeNovel = 0
@@ -80,7 +79,6 @@ class NWIndex():
self._novelIndex = {}
self._noteIndex = {}
self._textCounts = {}
self._firstTitle = {}
self._timeNovel = 0
self._timeNotes = 0
self._timeIndex = 0
@@ -103,7 +101,6 @@ class NWIndex():
self._novelIndex.pop(tHandle, None)
self._noteIndex.pop(tHandle, None)
self._textCounts.pop(tHandle, None)
self._firstTitle.pop(tHandle, None)
return
@@ -172,7 +169,6 @@ class NWIndex():
self._novelIndex = theData.get("novelIndex", {})
self._noteIndex = theData.get("noteIndex", {})
self._textCounts = theData.get("textCounts", {})
self._firstTitle = theData.get("firstTitle", {})
nowTime = round(time())
self._timeNovel = nowTime
@@ -198,7 +194,6 @@ class NWIndex():
"novelIndex" : self._novelIndex,
"noteIndex" : self._noteIndex,
"textCounts" : self._textCounts,
"firstTitle" : self._firstTitle,
}, outFile, indent=2)
except Exception:
logger.error("Failed to save index file")
@@ -220,7 +215,6 @@ class NWIndex():
self._checkNovelNoteIndex("novelIndex")
self._checkNovelNoteIndex("noteIndex")
self._checkTextCounts()
self._checkFirstTitles()
self.indexBroken = False
except Exception:
@@ -291,7 +285,6 @@ class NWIndex():
"tags" : [],
"updated" : round(time()),
}
self._firstTitle[tHandle] = ["H0", "T000000"]
if itemLayout == nwItemLayout.NOTE:
self._novelIndex.pop(tHandle, None)
self._noteIndex[tHandle] = {}
@@ -400,9 +393,6 @@ class NWIndex():
"updated" : round(time()),
}
if self._firstTitle[tHandle][0] == "H0":
self._firstTitle[tHandle] = [hDepth, sTitle]
if hText != "":
if isNovel:
if tHandle in self._novelIndex:
@@ -678,11 +668,6 @@ class NWIndex():
return theToC
def getFirstTitle(self, tHandle):
"""Return the level and location of the first title of a handle.
"""
return self._firstTitle.get(tHandle, ["H0", "T000000"])
def getCounts(self, tHandle, sTitle=None):
"""Returns the counts for a file, or a section of a file
starting at title sTitle if it is provided.
@@ -924,22 +909,4 @@ class NWIndex():
return
def _checkFirstTitles(self):
"""Scan the first titles index for errors.
Waring: This function raises exceptions.
"""
for tHandle in self._firstTitle:
if not isHandle(tHandle):
raise KeyError("firstTitle key is not a handle")
tEntry = self._firstTitle[tHandle]
if len(tEntry) != 2:
raise IndexError("firstTitle[a] expected 2 values")
if not tEntry[0] in self.H_VALID:
raise ValueError("firstTitle[a][0] is not a header level")
if not isTitleTag(tEntry[1]):
raise ValueError("firstTitle[a][1] is not a title tag")
return
# END Class NWIndex
+5 -5
View File
@@ -1,13 +1,13 @@
<?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="1.2a0" hexVersion="0x010200a0" fileVersion="1.2" timeStamp="2021-01-31 22:28:54">
<novelWriterXML appVersion="1.2a0" hexVersion="0x010200a0" fileVersion="1.2" timeStamp="2021-02-01 23:18:32">
<project>
<name>Sample Project</name>
<title>Sample Project</title>
<author>Jane Smith</author>
<author>Jay Doh</author>
<saveCount>881</saveCount>
<autoCount>157</autoCount>
<editTime>42668</editTime>
<saveCount>886</saveCount>
<autoCount>158</autoCount>
<editTime>42826</editTime>
</project>
<settings>
<doBackup>False</doBackup>
@@ -120,7 +120,7 @@
<charCount>1810</charCount>
<wordCount>318</wordCount>
<paraCount>8</paraCount>
<cursorPos>1880</cursorPos>
<cursorPos>219</cursorPos>
</item>
<item handle="bc0cbd2a407f3" order="2" parent="e7ded148d6e4a">
<name>Another Scene</name>
@@ -567,67 +567,5 @@
259,
3
]
},
"firstTitle": {
"7a992350f3eb6": [
"H1",
"T000001"
],
"8c58a65414c23": [
"H0",
"T000000"
],
"88d59a277361b": [
"H2",
"T000001"
],
"db7e733775d4d": [
"H1",
"T000001"
],
"fb609cd8319dc": [
"H2",
"T000001"
],
"88243afbe5ed8": [
"H3",
"T000001"
],
"f96ec11c6a3da": [
"H3",
"T000001"
],
"846352075de7d": [
"H2",
"T000001"
],
"441420a886d82": [
"H2",
"T000001"
],
"eb103bc70c90c": [
"H3",
"T000001"
],
"f8c0562e50f1b": [
"H3",
"T000001"
],
"47666c91c7ccf": [
"H3",
"T000001"
],
"4c4f28287af27": [
"H1",
"T000001"
],
"2426c6f0ca922": [
"H1",
"T000001"
],
"04468803b92e1": [
"H1",
"T000001"
]
}
}
-53
View File
@@ -591,11 +591,6 @@ def testCoreIndex_ExtractData(nwMinimal, dummyGUI):
assert wC == 16
assert pC == 2
# getFirstTitle
# =============
assert theIndex.getFirstTitle(cHandle) == ["H1", "T000001"]
# Novel Stats
# ===========
@@ -1166,51 +1161,3 @@ def testCoreIndex_CheckTextCounts(dummyGUI):
theIndex._checkTextCounts()
# END Test testCoreIndex_CheckTextCounts
@pytest.mark.core
def testCoreIndex_CheckFirstTitle(dummyGUI):
"""Test the first title checker.
"""
theProject = NWProject(dummyGUI)
theIndex = NWIndex(theProject, dummyGUI)
# Valid Index
theIndex._firstTitle = {
"53b69b83cdafc": ["H1", "T000001"],
"974e400180a99": ["H0", "T000000"],
}
assert theIndex._checkFirstTitles() is None
# Invalid Handle
theIndex._firstTitle = {
"53b69b83cdafc": ["H1", "T000001"],
"h74e400180a99": ["H0", "T000000"],
}
with pytest.raises(KeyError):
theIndex._checkFirstTitles()
# Wrong Length
theIndex._firstTitle = {
"53b69b83cdafc": ["H1", "T000001"],
"974e400180a99": ["H0", "T000000", "stuff"],
}
with pytest.raises(IndexError):
theIndex._checkFirstTitles()
# Wrong Header
theIndex._firstTitle = {
"53b69b83cdafc": ["H1", "T000001"],
"974e400180a99": ["XX", "T000000"],
}
with pytest.raises(ValueError):
theIndex._checkFirstTitles()
# Wrong Title
theIndex._firstTitle = {
"53b69b83cdafc": ["H1", "T000001"],
"974e400180a99": ["H0", "INVALID"],
}
with pytest.raises(ValueError):
theIndex._checkFirstTitles()
# END Test testCoreIndex_CheckFirstTitle