1185.75.4
by Hans Ulrich Niedermann
Implement the bzr documentation/information autogeneration plan: |
1 |
#!/usr/bin/python
|
2 |
||
3 |
# Copyright 2005 Canonical Ltd.
|
|
4 |
||
5 |
# This program is free software; you can redistribute it and/or modify
|
|
6 |
# it under the terms of the GNU General Public License as published by
|
|
7 |
# the Free Software Foundation; either version 2 of the License, or
|
|
8 |
# (at your option) any later version.
|
|
9 |
||
10 |
# This program is distributed in the hope that it will be useful,
|
|
11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
# GNU General Public License for more details.
|
|
14 |
||
15 |
# You should have received a copy of the GNU General Public License
|
|
16 |
# along with this program; if not, write to the Free Software
|
|
17 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
1185.74.13
by James Blackwell
Final wrapup on doc generation |
18 |
"""%(prog)s - generate information from built-in bzr help
|
19 |
||
20 |
%(prog)s creates a file with information on bzr in one of
|
|
21 |
several different output formats:
|
|
1185.75.5
by Hans Ulrich Niedermann
bzr-infogen.py cosmetics |
22 |
|
23 |
man man page
|
|
24 |
bash_completion bash completion script
|
|
25 |
...
|
|
26 |
||
1185.74.13
by James Blackwell
Final wrapup on doc generation |
27 |
Examples:
|
28 |
||
29 |
python2.4 generated-docs.py man
|
|
30 |
python2.4 generated-docs.py bash_completion
|
|
31 |
||
32 |
Run "%(prog)s --help" for the option reference.
|
|
1185.75.4
by Hans Ulrich Niedermann
Implement the bzr documentation/information autogeneration plan: |
33 |
"""
|
34 |
||
35 |
import sys |
|
1185.74.23
by James Blackwell
pep8ifying |
36 |
from optparse import OptionParser |
37 |
||
1185.74.13
by James Blackwell
Final wrapup on doc generation |
38 |
import tools.doc_generate |
1185.75.4
by Hans Ulrich Niedermann
Implement the bzr documentation/information autogeneration plan: |
39 |
|
40 |
def main(argv): |
|
41 |
parser = OptionParser(usage="%prog [options] OUTPUT_FORMAT") |
|
1185.74.12
by James Blackwell
Better help for doc_generate |
42 |
|
1185.75.4
by Hans Ulrich Niedermann
Implement the bzr documentation/information autogeneration plan: |
43 |
parser.add_option("-s", "--show-filename", |
44 |
action="store_true", dest="show_filename", default=False, |
|
45 |
help="print default filename on stdout") |
|
1185.74.12
by James Blackwell
Better help for doc_generate |
46 |
|
47 |
parser.add_option("-o", "--output", dest="filename", metavar="FILE", |
|
48 |
help="write output to FILE") |
|
49 |
||
50 |
parser.add_option("-b", "--bzr-name", |
|
51 |
dest="bzr_name", default="bzr", metavar="EXEC_NAME", |
|
52 |
help="name of bzr executable") |
|
53 |
||
54 |
parser.add_option("-e", "--examples", |
|
1185.74.23
by James Blackwell
pep8ifying |
55 |
action="callback", callback=print_extended_help, |
56 |
help="Examples of ways to call generate_doc") |
|
1185.74.12
by James Blackwell
Better help for doc_generate |
57 |
|
58 |
||
1185.75.4
by Hans Ulrich Niedermann
Implement the bzr documentation/information autogeneration plan: |
59 |
(options, args) = parser.parse_args(argv) |
60 |
||
61 |
if len(args) != 2: |
|
1185.74.12
by James Blackwell
Better help for doc_generate |
62 |
parser.print_help() |
63 |
sys.exit(1) |
|
1185.75.4
by Hans Ulrich Niedermann
Implement the bzr documentation/information autogeneration plan: |
64 |
|
65 |
infogen_type = args[1] |
|
1185.74.13
by James Blackwell
Final wrapup on doc generation |
66 |
infogen_mod = tools.doc_generate.get_module(infogen_type) |
1185.75.4
by Hans Ulrich Niedermann
Implement the bzr documentation/information autogeneration plan: |
67 |
|
68 |
if options.filename: |
|
69 |
outfilename = options.filename |
|
70 |
else: |
|
71 |
outfilename = infogen_mod.get_filename(options) |
|
72 |
||
73 |
if outfilename == "-": |
|
74 |
outfile = sys.stdout |
|
75 |
else: |
|
76 |
outfile = open(outfilename,"w") |
|
77 |
||
78 |
if options.show_filename and (outfilename != "-"): |
|
79 |
print >>sys.stdout, outfilename |
|
80 |
||
81 |
infogen_mod.infogen(options, outfile) |
|
82 |
||
1185.74.12
by James Blackwell
Better help for doc_generate |
83 |
def print_extended_help(option, opt, value, parser): |
1185.74.23
by James Blackwell
pep8ifying |
84 |
""" Program help examples
|
85 |
||
86 |
Prints out the examples stored in the docstring.
|
|
87 |
||
88 |
"""
|
|
1185.50.63
by John Arbash Meinel
[merge] James Blackwell, Hans Ulrich Niedermann: manpage fixes |
89 |
print >>sys.stdout, __doc__ % {"prog":sys.argv[0]} |
90 |
sys.exit(0) |
|
1185.75.4
by Hans Ulrich Niedermann
Implement the bzr documentation/information autogeneration plan: |
91 |
|
92 |
if __name__ == '__main__': |
|
93 |
main(sys.argv) |