From f4e75c6395310fa4b119d3eaa9a4a9f8913df200 Mon Sep 17 00:00:00 2001 From: "Pedro F. Giffuni" Date: Tue, 12 May 2015 03:27:06 +0000 Subject: Update to ficl 4.1.0 (latest release on sourceforge) --- doc/source/generate.py | 244 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 244 insertions(+) create mode 100644 doc/source/generate.py (limited to 'doc/source/generate.py') diff --git a/doc/source/generate.py b/doc/source/generate.py new file mode 100644 index 000000000000..36a4406320ad --- /dev/null +++ b/doc/source/generate.py @@ -0,0 +1,244 @@ +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 + """ +\n + + + +\n + + + + + +\n + +
+ + + +""" + heading + """ + +
+

+Index

+""") + + print("

\n") + + + +def ficlPageFooter(): + print("\n

\n") + + + +sizeArray = [7, 5, 4, 3, 2] +indentLevel = 0 +sections = None + +def ficlHeader(level, color, bgcolor, heading): + global sizeArray + size = str(sizeArray[level]) + + global indentLevel + global sections + while (indentLevel < level): + indentLevel += 1 +# sys.stderr.write("adding 1 to indentLevel, it's now " + str(indentLevel) + "\n\n") + sections.append([]) + while (indentLevel > level): + indentLevel -= 1 + subheadings = sections.pop() +# sys.stderr.write("indentLevel is " + str(indentLevel) + ", subheadings is " + str(subheadings) + ", len(sections) is " + str(len(sections)) + ", sections is " + str(sections) + "\n\n") + sections[indentLevel - 1][-1][1] = subheadings + entry = [heading, [] ] +# sys.stderr.write("indentLevel is " + str(indentLevel) + ", len(sections) is " + str(len(sections)) + ", sections is " + str(sections) + "\n\n") +# sys.stderr.flush() + sections[indentLevel - 1].append(entry) + + 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("") + 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) + + -- cgit v1.3