#!/usr/bin/env python3 import sys oldexcepthook = sys.excepthook def newexcepthook(type,value,traceback): oldexcepthook(type,value,traceback) input("Press ENTER to quit.") sys.excepthook = newexcepthook import os p = os.path.join pUp = os.path.dirname s = False if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'): s = os.path.realpath(sys.executable) else: s = os.path.realpath(__file__) sp = pUp(s) # script start import html import shutil def getDescription(dir): desc = "No description" try: with open(p(dir,"description.txt")) as dfile: desc = dfile.read().strip(" \t\r\n") except: pass return desc def getTags(dir): tags = ["none"] try: with open(p(dir,"tags.txt")) as tfile: tags = tfile.read().strip(" \t\r\n").split(" ") except: pass return tags def getModList(dir, modlist = {}, rootdir = False): if rootdir == False: rootdir = dir for root,dirs,files in os.walk(dir): for file in sorted(dirs): ffile = p(root,file) lfile = ffile.replace(rootdir + os.path.sep,"",1) modname = ffile.replace(dir + os.path.sep,"",1) activated = True if modname[0] == "-": modname = modname[1:] activated = False if modname[0] == "[" and modname[-1] == "]": getModList(ffile,modlist,rootdir) continue fmodname = p(pUp(lfile),modname) modlist[ffile] = { "modname": modname, "fmodname": fmodname, "activated": activated } break return modlist def makeHeading(title,id,size = 1): return '# ' +html.escape(title)+ '\n' def readTags(): tags = {} with open(p(sp,"tags.txt"),encoding="utf-8") as tfile: for line in tfile: line = line.strip(" \t\r\n") if line == "": continue tagSplit = line.split(" ",1) tags[tagSplit[0]] = tagSplit[1] return tags def main(): opusPath = pUp(sp) ofileHtml = p(opusPath,"docs","index.html") ofileMd = p(opusPath,"docs","index.md") ofile = open(ofileHtml,"w",encoding="utf-8") ofile.write('''\ opus-nt - Mod Documentation \ ''') tags = readTags() ofile.write(makeHeading("Tags","tags")) ofile.write('''\ ''') for tag in tags: ofile.write(' \n') ofile.write('
TagDescription
' +html.escape(tag)+ '' +html.escape(tags[tag])+ '
') modPaths = [] for root,dirs,files in os.walk(opusPath): for file in sorted(dirs): ffile = p(root,file) lfile = ffile.replace(opusPath + os.path.sep,"",1) if lfile.startswith("mods"): modPaths.append(ffile) break for modPath in modPaths: modList = getModList(modPath,{}) lmodPath = modPath.replace(opusPath + os.path.sep,"",1) ofile.write(makeHeading("Mods: " +lmodPath,lmodPath)) ofile.write(html.escape(getDescription(modPath))+ "
\n") ofile.write("\n") ofile.write(' \n') for modk in modList: mod = modList[modk] ofile.write(' \n') ofile.write("
ModTagsDescription
' +html.escape(pUp(mod["fmodname"]).replace("/","\\"))+ '\\' +html.escape(mod["modname"])+ '' +html.escape(", ".join(getTags(modk)))+ '' +html.escape(getDescription(modk))+ '

\n") ofile.write('\n') ofile.close() shutil.copyfile(ofileHtml,ofileMd) main()