1551.3.11
by Aaron Bentley
Merge from Robert |
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
|
|
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:
|
|
22 |
||
23 |
man man page
|
|
24 |
bash_completion bash completion script
|
|
25 |
...
|
|
26 |
||
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.
|
|
33 |
"""
|
|
34 |
||
35 |
import sys |
|
36 |
from optparse import OptionParser |
|
37 |
||
38 |
import tools.doc_generate |
|
39 |
||
40 |
def main(argv): |
|
1821.1.1
by Alexander Belchenko
win32 installer for bzr.dev.0.9 |
41 |
parser = OptionParser(usage="""%prog [options] OUTPUT_FORMAT |
42 |
||
43 |
Available OUTPUT_FORMAT:
|
|
44 |
||
45 |
man man page
|
|
46 |
rstx man page in ReStructuredText format
|
|
47 |
bash_completion bash completion script""") |
|
1551.3.11
by Aaron Bentley
Merge from Robert |
48 |
|
49 |
parser.add_option("-s", "--show-filename", |
|
50 |
action="store_true", dest="show_filename", default=False, |
|
51 |
help="print default filename on stdout") |
|
52 |
||
53 |
parser.add_option("-o", "--output", dest="filename", metavar="FILE", |
|
54 |
help="write output to FILE") |
|
55 |
||
56 |
parser.add_option("-b", "--bzr-name", |
|
57 |
dest="bzr_name", default="bzr", metavar="EXEC_NAME", |
|
58 |
help="name of bzr executable") |
|
59 |
||
60 |
parser.add_option("-e", "--examples", |
|
61 |
action="callback", callback=print_extended_help, |
|
62 |
help="Examples of ways to call generate_doc") |
|
63 |
||
64 |
||
65 |
(options, args) = parser.parse_args(argv) |
|
66 |
||
67 |
if len(args) != 2: |
|
68 |
parser.print_help() |
|
69 |
sys.exit(1) |
|
70 |
||
71 |
infogen_type = args[1] |
|
72 |
infogen_mod = tools.doc_generate.get_module(infogen_type) |
|
73 |
||
74 |
if options.filename: |
|
75 |
outfilename = options.filename |
|
76 |
else: |
|
77 |
outfilename = infogen_mod.get_filename(options) |
|
78 |
||
79 |
if outfilename == "-": |
|
80 |
outfile = sys.stdout |
|
81 |
else: |
|
82 |
outfile = open(outfilename,"w") |
|
83 |
||
84 |
if options.show_filename and (outfilename != "-"): |
|
85 |
print >>sys.stdout, outfilename |
|
86 |
||
87 |
infogen_mod.infogen(options, outfile) |
|
88 |
||
89 |
def print_extended_help(option, opt, value, parser): |
|
90 |
""" Program help examples
|
|
91 |
||
92 |
Prints out the examples stored in the docstring.
|
|
93 |
||
94 |
"""
|
|
95 |
print >>sys.stdout, __doc__ % {"prog":sys.argv[0]} |
|
96 |
sys.exit(0) |
|
97 |
||
98 |
if __name__ == '__main__': |
|
99 |
main(sys.argv) |