-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-docs.py
executable file
·79 lines (59 loc) · 2.18 KB
/
generate-docs.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/sh
"""":
python -c "" 2>/dev/null && exec python $0 ${1+"$@"}
python3 -c "" 2>/dev/null && exec python3 $0 ${1+"$@"}
python2 -c "" 2>/dev/null && exec python2 $0 ${1+"$@"}
echo "Could not find a python interpreter."
exit 1
"""
# The above will attempt to find a the best available python interpreter
# available to run the docs. This a requirement because this is built on
# multiple series and there is no standard python to install for each one.
#
# The code will first run as shell (sh), find the correct python interpreter
# then run the same file as python, which will ignore the shell, because it's
# seen as a python doc string.
# Copyright 2013 Canonical Ltd.
# Licensed under the AGPLv3, see LICENCE file for details.
import os
import sys
from optparse import OptionParser
from jujuman import JujuMan
GENERATORS = {
'man': JujuMan
}
# Insert the directory that this module is in into the python path.
sys.path.insert(0, (os.path.dirname(__file__)))
def main(argv):
parser = OptionParser(usage="""%prog [options] OUTPUT_FORMAT
Available OUTPUT_FORMAT:
man man page
And that is all for now.""")
parser.add_option("-s", "--show-filename",
action="store_true", dest="show_filename", default=False,
help="print default filename on stdout")
parser.add_option("-o", "--output", dest="filename", metavar="FILE",
help="write output to FILE")
(options, args) = parser.parse_args(argv)
if len(args) != 2:
parser.print_help()
sys.exit(1)
try:
doc_generator = GENERATORS[args[1]]()
except KeyError as e:
sys.stderr.write("Unknown documentation generator %r\n" % e.message)
sys.exit(1)
if options.filename:
outfilename = options.filename
else:
outfilename = doc_generator.get_filename(options)
if outfilename == "-":
outfile = sys.stdout
else:
outfile = open(outfilename, "w")
if options.show_filename and (outfilename != "-"):
sys.stdout.write(outfilename)
sys.stdout.write('\n')
doc_generator.write_documentation(options, outfile)
if __name__ == "__main__":
main(sys.argv)