Project

General

Profile

root / trunk / doc / manual / gen_cli_doc.py @ 705

1
import haizea.cli.commands as cmd
2
import haizea.cli.rpc_commands as rpccmd
3
from docutils.core import publish_string
4
import re
5
import textwrap
6

    
7
commands = [cmd.haizea, rpccmd.haizea_request_lease, rpccmd.haizea_cancel_lease, rpccmd.haizea_list_leases,
8
            rpccmd.haizea_show_queue, rpccmd.haizea_list_hosts, cmd.haizea_generate_configs, cmd.haizea_generate_scripts, cmd.haizea_convert_data]
9

    
10

    
11

    
12
for command in commands:
13
    c = command([])
14
    print "\\section{\\texttt{%s}}" % command.name
15
    print
16
    doc = textwrap.dedent(command.__doc__).strip()
17
    latexdoc = publish_string(doc,  writer_name="latex")
18
    latexdoc = re.compile("\\\\begin{document}\n\n\\\\setlength{\\\\locallinewidth}{\\\\linewidth}\n\n(.*)\\\\end{document}", flags=re.DOTALL).search(latexdoc)
19
    print latexdoc.group(1)
20
    print
21
    print "\\begin{center}\\begin{tabular}{|l|p{6cm}|}"
22
    print "\\hline"
23
    print "\\sffamily\\bfseries Option & \\sffamily\\bfseries Description \\\\ \\hline\\hline"
24
    opts = c.optparser.option_list
25
    c.optparser.formatter.store_option_strings(c.optparser)
26
    for opt in opts:
27
        if opt.action != "help":
28
            opt_string = c.optparser.formatter.option_strings[opt]            
29
            opt_help = textwrap.dedent(opt.help).strip()
30
            latexhelp = publish_string(opt_help,  writer_name="latex")
31
            latexhelp = re.compile("\\\\begin{document}\n\n\\\\setlength{\\\\locallinewidth}{\\\\linewidth}\n\n(.*)\\\\end{document}", flags=re.DOTALL).search(latexhelp)
32
            latexhelp = latexhelp.group(1)
33
            print "\\texttt{%s} & \\sffamily %s \\\\ \\hline" % (opt_string, latexhelp)
34
    print "\\end{tabular}\\end{center}"
35
    print
36