Added code to write contents txt and json files on project close
This commit is contained in:
@@ -39,8 +39,8 @@ class nwFiles():
|
|||||||
PROJ_FILE = "nwProject.nwx"
|
PROJ_FILE = "nwProject.nwx"
|
||||||
PROJ_DICT = "wordlist.txt"
|
PROJ_DICT = "wordlist.txt"
|
||||||
PROJ_LOCK = "nwProject.lock"
|
PROJ_LOCK = "nwProject.lock"
|
||||||
TOC_TXT = "ToC.txt"
|
TOC_TXT = "content.txt"
|
||||||
TOC_JSON = "ToC.json"
|
TOC_JSON = "content.json"
|
||||||
SESS_INFO = "sessionInfo.log"
|
SESS_INFO = "sessionInfo.log"
|
||||||
INDEX_FILE = "tagsIndex.json"
|
INDEX_FILE = "tagsIndex.json"
|
||||||
OPTS_FILE = "guiOptions.json"
|
OPTS_FILE = "guiOptions.json"
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import json
|
||||||
import nw
|
import nw
|
||||||
|
|
||||||
from os import path, mkdir, listdir, unlink, rename, rmdir
|
from os import path, mkdir, listdir, unlink, rename, rmdir
|
||||||
@@ -566,6 +567,7 @@ class NWProject():
|
|||||||
def closeProject(self):
|
def closeProject(self):
|
||||||
"""Close the current project and clear all meta data.
|
"""Close the current project and clear all meta data.
|
||||||
"""
|
"""
|
||||||
|
self.projTree.writeToCFiles()
|
||||||
self._appendSessionStats()
|
self._appendSessionStats()
|
||||||
self._clearLockFile()
|
self._clearLockFile()
|
||||||
self.clearProject()
|
self.clearProject()
|
||||||
@@ -1300,6 +1302,50 @@ class NWTree():
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def writeToCFiles(self):
|
||||||
|
"""Write the convenience table of contents files in the root of
|
||||||
|
the project directory. These files are there to assist the user
|
||||||
|
if they wish to browse the stored files.
|
||||||
|
"""
|
||||||
|
tocText = path.join(self.theProject.projPath, nwFiles.TOC_TXT)
|
||||||
|
tocJson = path.join(self.theProject.projPath, nwFiles.TOC_JSON)
|
||||||
|
|
||||||
|
jsonData = []
|
||||||
|
try:
|
||||||
|
# Dump the text
|
||||||
|
with open(tocText, mode="w", encoding="utf8") as outFile:
|
||||||
|
outFile.write("\n")
|
||||||
|
outFile.write(" Table of Contents\n")
|
||||||
|
outFile.write("===================\n")
|
||||||
|
outFile.write("\n")
|
||||||
|
outFile.write(" %-25s %-9s %s\n" %("File Name","Class","Document Label"))
|
||||||
|
outFile.write("-"*80+"\n")
|
||||||
|
for tHandle in sorted(self._treeOrder):
|
||||||
|
tItem = self.__getitem__(tHandle)
|
||||||
|
if tItem is None:
|
||||||
|
continue
|
||||||
|
tFile = tHandle+".nwd"
|
||||||
|
if path.isfile(path.join(self.theProject.projContent, tFile)):
|
||||||
|
outFile.write(" %-25s %-9s %s\n" %(
|
||||||
|
path.join("content", tFile),
|
||||||
|
tItem.itemClass.name,
|
||||||
|
tItem.itemName,
|
||||||
|
))
|
||||||
|
jsonData.append([
|
||||||
|
path.join("content", tFile),
|
||||||
|
tItem.itemClass.name,
|
||||||
|
tItem.itemName,
|
||||||
|
])
|
||||||
|
|
||||||
|
# Dump the JSON
|
||||||
|
with open(tocJson, mode="w+", encoding="utf8") as outFile:
|
||||||
|
outFile.write(json.dumps(jsonData, indent=2))
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(str(e))
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
# Tree Structure Methods
|
# Tree Structure Methods
|
||||||
##
|
##
|
||||||
|
|||||||
Reference in New Issue
Block a user