import cStringIO import os import re import shutil import string import sys outputStart = None navBarEntries = {} def ficlLinkEntry(file, title): print("" + title + "
\n") currentNavBarName = None def ficlAddToNavBarAs(name): global currentNavBarName currentNavBarName = name def ficlPageHeader(heading): outputStart.write("""
![]() |
""" + heading + """ | ||
""") print(" |
|
") print("") print(heading) print(" |
\n") def ficlHeader1(heading): ficlHeader(1, "#004968", "#a0a0a0", heading) def ficlHeader2(heading): ficlHeader(2, "#004968", "#b8b8b8", heading) def ficlHeader3(heading): ficlHeader(3, "#004968", "#d0d0d0", heading) def ficlHeader4(heading): ficlHeader(4, "#004968", "#e8e8e8", heading) def collapse(s): return string.join(s.split(), "").replace("'", "").replace("&", "").replace('"', "").replace('<', "").replace('>', "").replace('.', "").replace('?', "") def dump(f, sections): for section in sections: sys.stderr.write("sections is " + str(section) + "\n") name = section[0] f.write("" + name + "\n") if len(section[1]) != 0: f.write(" \n") dump(f, section[1]) f.write("
\n") def process(inputfilename, outputfilename): print "generating " + inputfilename global indentLevel indentLevel = 0 global sections sections = [] global currentNavBarName input = open(inputfilename, "r") data = input.read().replace("\r", "") input.close() chunks = data.split("") output = cStringIO.StringIO() global outputStart outputStart = cStringIO.StringIO() stdout = sys.stdout fauxGlobals = { } fauxGlobals.update(globals()) fauxGlobals['__name__'] = '__ficlDocs__' fauxGlobals['__doc__'] = inputfilename fauxGlobals['outputStart'] = outputStart sys.stdout = output if (chunks[0] != None): output.write(chunks[0]) for chunk in chunks[1:]: (code, verbatim) = chunk.split("?>") code = code.lstrip() if (code[0] == "="): execution = "eval" code = code[1:].lstrip() else: execution = "exec" compiled = compile(code, "[unknown]", execution) if (execution == "eval"): output.write(str(eval(compiled))) else: exec compiled output.write(verbatim) sys.stdout = stdout f = open(outputfilename, "w") f.write(outputStart.getvalue()) f.write("
\n") keys = navBarEntries.keys() keys.sort() for name in keys: filename = navBarEntries[name] f.write("") name = name.replace(" ", " ") f.write("" + name + "") f.write("
\n") # This doesn't look as pretty as I wanted, so I'm turning it off. --lch # if (name == currentNavBarName) and (len(sections) > 0): # f.write("\n") # dump(f, sections[0]) # f.write("
\n") f.write(output.getvalue()) f.close() ## ## First, find all the documents in the current directory, ## and look for their navBar entry. ## for filename in os.listdir("."): if filename[-3:] == ".ht": file = open(filename, "rb") for line in file.readlines(): navBar = "ficlAddToNavBarAs(\"" if line.strip().startswith(navBar): (a, name, b) = line.split('"') navBarEntries[name] = filename + "ml" break file.close() navBarEntries["Download"] = "http://sourceforge.net/project/showfiles.php?group_id=24441" ignored = re.compile("^((.*\.pyc?)|(.*\.zip)|\.|(\.\.))$") ## ## Second, build the doc tree (in ..), processing as necessary. ## def visit(unused, directory, names): for file in names: if ignored.search(file): continue input = directory + "/" + file output = "../" + input if input[-3:].lower() == ".ht": process(input, output + "ml") elif os.path.isdir(input): if not os.path.isdir(output): os.mkdir(output) else: try: shutil.copy2(input, output) except IOError: ## Ignore file-copy errors. It's probably ## a read-only file that doesn't change. ## Lazy, I know. --lch None os.path.walk(".", visit, None)