~bzr-pqm/bzr/bzr.dev

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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/python

# Copyright 2005 Canonical Ltd.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

"""bzr-infogen.py - generate information from built-in bzr help

bzr-infogen.py creates a file with information on bzr in one of
several different output formats:\n

    man              man page
    bash_completion  bash completion script
    ...

Run "bzr-infogen.py --help" for usage information.
"""

# Plan (devised by jblack and ndim 2005-12-10):
#   * one generate_doc.py script in top level dir right beside bzr
#   * one doc_generate/ directory (python module)
#     We did not put the stuff into bzrlib because we thought
#     that all this stuff doesn't need to get loaded every time you run bzr.
#     However, I'm not sure that is actually true (ndim 2005-12-11).
#   * several generator scripts like
#           doc_generate/autodoc_man_page.py
#                        autodoc_docbook_xml.py
#                        autodoc_html.py
#                        autodoc_bash_completion.py
#                        autodoc_zsh_completion.py
#   * scripts are called by running something like
#     "python2.4 generated_docs.py --man-page"         or
#     "python2.4 generated_docs.py --bash-completion"   or
#     "pytohn2.4 generated_docs.py --all"
#     
#   * one test case which iterates through all gen_*.py scripts and
#     tries to generate all the file types, checking that all generators
#     work (we'll let bzrinfogen/__init__.py provide the list to walk through)
#   * those generator scripts walk through the command and option data
#     structures to extract the required information
#   * the actual names are just prototypes and subject to change


import sys
import doc_generate

descr = """generated-docs.py creates a file with information on bzr in a variety
of output formats. Currently included: man and bash_completion.

Examples: 

    python2.4 generated-docs.py --man
    python2.4 generated-docs.py --bash_completion
    python2.4 generated-docs.py --all
"""

def main(argv):
    from optparse import OptionParser
    parser = OptionParser(usage="%prog [options] OUTPUT_FORMAT")

    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")

    parser.add_option("-b", "--bzr-name",
                      dest="bzr_name", default="bzr", metavar="EXEC_NAME",
                      help="name of bzr executable")

    parser.add_option("-e", "--examples",
                       action="callback", callback=print_extended_help,
                       help="Examples of ways to call generate_doc")


    (options, args) = parser.parse_args(argv)

    if len(args) != 2:
        parser.print_help()
        sys.exit(1)

    infogen_type = args[1]
    infogen_mod = doc_generate.generate(infogen_type)

    if options.filename:
        outfilename = options.filename
    else:
        outfilename = infogen_mod.get_filename(options)

    if outfilename == "-":
        outfile = sys.stdout
    else:
        outfile = open(outfilename,"w")

    if options.show_filename and (outfilename != "-"):
        print >>sys.stdout, outfilename
    
    infogen_mod.infogen(options, outfile)

def print_extended_help(option, opt, value, parser):
    print >>sys.stdout, __doc__
    sys.exit(0)


if __name__ == '__main__':
    main(sys.argv)