File: documentgen.py

package info (click to toggle)
myghty 1.1-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 1,932 kB
  • ctags: 2,281
  • sloc: python: 11,705; makefile: 51
file content (44 lines) | stat: -rw-r--r-- 1,245 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import sys, re, os
import myghty.interp
import myghty.exception as exception

# document generation library

def genall(comps, component_root, output_dir):
    interp = myghty.interp.Interpreter( component_root = component_root)
    
    try:
        for comp in comps:
            gendoc(comp, interp, output_dir = output_dir)
    except exception.Error, e:
        sys.stderr.write(e.textformat())


def gendoc(doccomp, interp, output_dir):
    component = interp.load(doccomp)
    files = component.get_attribute('files')
    index = component.get_attribute('index')
    onepage = component.get_attribute('onepage')

    genfile(index + ".myt", interp, output_dir)

    for file in files:
        file += '.myt'
        genfile(file, interp, output_dir)

    genfile(index + ".myt", interp, output_dir, outfile = onepage + ".html", args = {'paged':'no'})



def genfile(file, interp, output_dir, outfile = None, args = {}):
    if outfile is None:
        outfile = re.sub(r"\..+$", "%s" % '.html', file)

    outfile = os.path.join(output_dir, outfile)
    print "%s -> %s" % (file, outfile)
    outbuf = open(outfile, "w")

    interp.execute(file, out_buffer = outbuf, request_args = args, raise_error = True)
        
    outbuf.close()