Skip intermediate steps when loading/saving json files, and always use 2 space indent
This commit is contained in:
+2
-3
@@ -690,8 +690,7 @@ class Config:
|
||||
if os.path.isfile(cacheFile):
|
||||
try:
|
||||
with open(cacheFile, mode="r", encoding="utf8") as inFile:
|
||||
theJson = inFile.read()
|
||||
theData = json.loads(theJson)
|
||||
theData = json.load(inFile)
|
||||
|
||||
for projPath in theData.keys():
|
||||
theEntry = theData[projPath]
|
||||
@@ -729,7 +728,7 @@ class Config:
|
||||
|
||||
try:
|
||||
with open(cacheTemp, mode="w+", encoding="utf8") as outFile:
|
||||
outFile.write(json.dumps(self.recentProj, indent=2))
|
||||
json.dump(self.recentProj, outFile, indent=2)
|
||||
except Exception as e:
|
||||
self.hasError = True
|
||||
self.errData.append("Could not save recent project cache")
|
||||
|
||||
+5
-10
@@ -159,8 +159,7 @@ class NWIndex():
|
||||
logger.debug("Loading index file")
|
||||
try:
|
||||
with open(indexFile, mode="r", encoding="utf8") as inFile:
|
||||
theJson = inFile.read()
|
||||
theData = json.loads(theJson)
|
||||
theData = json.load(inFile)
|
||||
except Exception as e:
|
||||
logger.error("Failed to load index file")
|
||||
logger.error(str(e))
|
||||
@@ -190,23 +189,18 @@ class NWIndex():
|
||||
"""Save the current index as a json file in the project meta
|
||||
data folder.
|
||||
"""
|
||||
indexFile = os.path.join(self.theProject.projMeta, nwFiles.INDEX_FILE)
|
||||
|
||||
logger.debug("Saving index file")
|
||||
if self.mainConf.debugInfo:
|
||||
nIndent = 2
|
||||
else:
|
||||
nIndent = None
|
||||
indexFile = os.path.join(self.theProject.projMeta, nwFiles.INDEX_FILE)
|
||||
|
||||
try:
|
||||
with open(indexFile, mode="w+", encoding="utf8") as outFile:
|
||||
outFile.write(json.dumps({
|
||||
json.dump({
|
||||
"tagIndex" : self.tagIndex,
|
||||
"refIndex" : self.refIndex,
|
||||
"novelIndex" : self.novelIndex,
|
||||
"noteIndex" : self.noteIndex,
|
||||
"textCounts" : self.textCounts,
|
||||
}, indent=nIndent))
|
||||
}, outFile, indent=2)
|
||||
except Exception as e:
|
||||
logger.error("Failed to save index file")
|
||||
logger.error(str(e))
|
||||
@@ -218,6 +212,7 @@ class NWIndex():
|
||||
"""Check that the entries in the index are valid and contain the
|
||||
elements it should.
|
||||
"""
|
||||
logger.debug("Checking index")
|
||||
self.indexBroken = False
|
||||
|
||||
try:
|
||||
|
||||
+2
-3
@@ -109,8 +109,7 @@ class OptionState():
|
||||
logger.debug("Loading GUI options file")
|
||||
try:
|
||||
with open(stateFile, mode="r", encoding="utf8") as inFile:
|
||||
theJson = inFile.read()
|
||||
theState = json.loads(theJson)
|
||||
theState = json.load(inFile)
|
||||
except Exception as e:
|
||||
logger.error("Failed to load GUI options file")
|
||||
logger.error(str(e))
|
||||
@@ -137,7 +136,7 @@ class OptionState():
|
||||
|
||||
try:
|
||||
with open(stateFile, mode="w+", encoding="utf8") as outFile:
|
||||
outFile.write(json.dumps(self.theState, indent=2))
|
||||
json.dump(self.theState, outFile, indent=2)
|
||||
except Exception as e:
|
||||
logger.error("Failed to save GUI options file")
|
||||
logger.error(str(e))
|
||||
|
||||
+1
-1
@@ -1024,7 +1024,7 @@ class NWProject():
|
||||
return True
|
||||
|
||||
def setTreeOrder(self, newOrder):
|
||||
"""A list representing the liner/flattened order of project
|
||||
"""A list representing the linear/flattened order of project
|
||||
items in the GUI project tree. The user can rearrange the order
|
||||
by drag-and-drop. Forwarded to the NWTree class.
|
||||
"""
|
||||
|
||||
+1
-1
@@ -177,7 +177,7 @@ class NWTree():
|
||||
|
||||
# Dump the JSON
|
||||
with open(tocJson, mode="w+", encoding="utf8") as outFile:
|
||||
outFile.write(json.dumps(jsonData, indent=2))
|
||||
json.dump(jsonData, outFile, indent=2)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(str(e))
|
||||
|
||||
@@ -362,7 +362,7 @@ class GuiWritingStats(QDialog):
|
||||
"novelWords": wA,
|
||||
"noteWords": wB,
|
||||
})
|
||||
outFile.write(json.dumps(jsonData, indent=2))
|
||||
json.dump(jsonData, outFile, indent=2)
|
||||
wSuccess = True
|
||||
|
||||
elif dataFmt == self.FMT_CSV:
|
||||
|
||||
Reference in New Issue
Block a user