~bzr-pqm/bzr/bzr.dev

1551.3.11 by Aaron Bentley
Merge from Robert
1
#!/usr/bin/python
2
3
# Copyright 2005 Canonical Ltd.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
4
#
1551.3.11 by Aaron Bentley
Merge from Robert
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
9
#
1551.3.11 by Aaron Bentley
Merge from Robert
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
14
#
1551.3.11 by Aaron Bentley
Merge from Robert
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
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
18
1551.3.11 by Aaron Bentley
Merge from Robert
19
"""%(prog)s - generate information from built-in bzr help
20
21
%(prog)s creates a file with information on bzr in one of
22
several different output formats:
23
24
    man              man page
25
    bash_completion  bash completion script
26
    ...
27
28
Examples: 
29
30
    python2.4 generated-docs.py man
31
    python2.4 generated-docs.py bash_completion
32
33
Run "%(prog)s --help" for the option reference.
34
"""
35
36
import sys
37
from optparse import OptionParser
38
39
import tools.doc_generate
40
41
def main(argv):
42
    parser = OptionParser(usage="%prog [options] OUTPUT_FORMAT")
43
44
    parser.add_option("-s", "--show-filename",
45
                      action="store_true", dest="show_filename", default=False,
46
                      help="print default filename on stdout")
47
48
    parser.add_option("-o", "--output", dest="filename", metavar="FILE",
49
                      help="write output to FILE")
50
51
    parser.add_option("-b", "--bzr-name",
52
                      dest="bzr_name", default="bzr", metavar="EXEC_NAME",
53
                      help="name of bzr executable")
54
55
    parser.add_option("-e", "--examples",
56
                      action="callback", callback=print_extended_help,
57
                      help="Examples of ways to call generate_doc")
58
59
60
    (options, args) = parser.parse_args(argv)
61
62
    if len(args) != 2:
63
        parser.print_help()
64
        sys.exit(1)
65
66
    infogen_type = args[1]
67
    infogen_mod = tools.doc_generate.get_module(infogen_type)
68
69
    if options.filename:
70
        outfilename = options.filename
71
    else:
72
        outfilename = infogen_mod.get_filename(options)
73
74
    if outfilename == "-":
75
        outfile = sys.stdout
76
    else:
77
        outfile = open(outfilename,"w")
78
79
    if options.show_filename and (outfilename != "-"):
80
        print >>sys.stdout, outfilename
81
    
82
    infogen_mod.infogen(options, outfile)
83
84
def print_extended_help(option, opt, value, parser):
85
    """ Program help examples
86
87
    Prints out the examples stored in the docstring. 
88
89
    """
90
    print >>sys.stdout, __doc__ % {"prog":sys.argv[0]}
91
    sys.exit(0)
92
93
if __name__ == '__main__':
94
    main(sys.argv)