~bzr-pqm/bzr/bzr.dev

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
18
19
"""bzr-infogen.py - generate information from built-in bzr help
20
1185.75.5 by Hans Ulrich Niedermann
bzr-infogen.py cosmetics
21
bzr-infogen.py creates a file with information on bzr in one of
1185.74.12 by James Blackwell
Better help for doc_generate
22
several different output formats:\n
1185.75.5 by Hans Ulrich Niedermann
bzr-infogen.py cosmetics
23
24
    man              man page
25
    bash_completion  bash completion script
26
    ...
27
28
Run "bzr-infogen.py --help" for usage information.
1185.75.4 by Hans Ulrich Niedermann
Implement the bzr documentation/information autogeneration plan:
29
"""
30
1185.75.5 by Hans Ulrich Niedermann
bzr-infogen.py cosmetics
31
# Plan (devised by jblack and ndim 2005-12-10):
1185.74.11 by James Blackwell
Updating plan
32
#   * one generate_doc.py script in top level dir right beside bzr
33
#   * one doc_generate/ directory (python module)
34
#     We did not put the stuff into bzrlib because we thought
1185.75.7 by Hans Ulrich Niedermann
more bzr-infogen docs
35
#     that all this stuff doesn't need to get loaded every time you run bzr.
36
#     However, I'm not sure that is actually true (ndim 2005-12-11).
1185.75.5 by Hans Ulrich Niedermann
bzr-infogen.py cosmetics
37
#   * several generator scripts like
1185.74.11 by James Blackwell
Updating plan
38
#           doc_generate/autodoc_man_page.py
39
#                        autodoc_docbook_xml.py
40
#                        autodoc_html.py
41
#                        autodoc_bash_completion.py
42
#                        autodoc_zsh_completion.py
1185.75.7 by Hans Ulrich Niedermann
more bzr-infogen docs
43
#   * scripts are called by running something like
1185.74.11 by James Blackwell
Updating plan
44
#     "python2.4 generated_docs.py --man-page"         or
45
#     "python2.4 generated_docs.py --bash-completion"   or
46
#     "pytohn2.4 generated_docs.py --all"
47
#     
1185.75.5 by Hans Ulrich Niedermann
bzr-infogen.py cosmetics
48
#   * one test case which iterates through all gen_*.py scripts and
49
#     tries to generate all the file types, checking that all generators
1185.75.7 by Hans Ulrich Niedermann
more bzr-infogen docs
50
#     work (we'll let bzrinfogen/__init__.py provide the list to walk through)
1185.75.5 by Hans Ulrich Niedermann
bzr-infogen.py cosmetics
51
#   * those generator scripts walk through the command and option data
52
#     structures to extract the required information
53
#   * the actual names are just prototypes and subject to change
54
55
1185.75.4 by Hans Ulrich Niedermann
Implement the bzr documentation/information autogeneration plan:
56
import sys
1185.74.8 by James Blackwell
Hacked up ndim's code
57
import doc_generate
1185.75.4 by Hans Ulrich Niedermann
Implement the bzr documentation/information autogeneration plan:
58
1185.74.12 by James Blackwell
Better help for doc_generate
59
descr = """generated-docs.py creates a file with information on bzr in a variety
60
of output formats. Currently included: man and bash_completion.
61
62
Examples: 
63
64
    python2.4 generated-docs.py --man
65
    python2.4 generated-docs.py --bash_completion
66
    python2.4 generated-docs.py --all
67
"""
1185.75.4 by Hans Ulrich Niedermann
Implement the bzr documentation/information autogeneration plan:
68
69
def main(argv):
70
    from optparse import OptionParser
71
    parser = OptionParser(usage="%prog [options] OUTPUT_FORMAT")
1185.74.12 by James Blackwell
Better help for doc_generate
72
1185.75.4 by Hans Ulrich Niedermann
Implement the bzr documentation/information autogeneration plan:
73
    parser.add_option("-s", "--show-filename",
74
                      action="store_true", dest="show_filename", default=False,
75
                      help="print default filename on stdout")
1185.74.12 by James Blackwell
Better help for doc_generate
76
77
    parser.add_option("-o", "--output", dest="filename", metavar="FILE",
78
                      help="write output to FILE")
79
80
    parser.add_option("-b", "--bzr-name",
81
                      dest="bzr_name", default="bzr", metavar="EXEC_NAME",
82
                      help="name of bzr executable")
83
84
    parser.add_option("-e", "--examples",
85
                       action="callback", callback=print_extended_help,
86
                       help="Examples of ways to call generate_doc")
87
88
1185.75.4 by Hans Ulrich Niedermann
Implement the bzr documentation/information autogeneration plan:
89
    (options, args) = parser.parse_args(argv)
90
91
    if len(args) != 2:
1185.74.12 by James Blackwell
Better help for doc_generate
92
        parser.print_help()
93
        sys.exit(1)
1185.75.4 by Hans Ulrich Niedermann
Implement the bzr documentation/information autogeneration plan:
94
95
    infogen_type = args[1]
1185.74.10 by James Blackwell
Fixing up autodoc
96
    infogen_mod = doc_generate.generate(infogen_type)
1185.75.4 by Hans Ulrich Niedermann
Implement the bzr documentation/information autogeneration plan:
97
98
    if options.filename:
99
        outfilename = options.filename
100
    else:
101
        outfilename = infogen_mod.get_filename(options)
102
103
    if outfilename == "-":
104
        outfile = sys.stdout
105
    else:
106
        outfile = open(outfilename,"w")
107
108
    if options.show_filename and (outfilename != "-"):
109
        print >>sys.stdout, outfilename
110
    
111
    infogen_mod.infogen(options, outfile)
112
1185.74.12 by James Blackwell
Better help for doc_generate
113
def print_extended_help(option, opt, value, parser):
114
    print >>sys.stdout, __doc__
115
    sys.exit(0)
116
1185.75.4 by Hans Ulrich Niedermann
Implement the bzr documentation/information autogeneration plan:
117
118
if __name__ == '__main__':
119
    main(sys.argv)