~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to tools/generate_docs.py

  • Committer: Aaron Bentley
  • Date: 2005-12-15 06:48:46 UTC
  • mto: This revision was merged to the branch mainline in revision 1533.
  • Revision ID: aaron.bentley@utoronto.ca-20051215064846-aa6cb6c42313c8e3
Updated NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
 
 
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
 
import os
36
 
import sys
37
 
from optparse import OptionParser
38
 
 
39
 
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
40
 
 
41
 
import bzrlib
42
 
from bzrlib import (
43
 
    commands,
44
 
    # Don't remove the following import, it triggers a format registration that
45
 
    # avoid http://pad.lv/956860
46
 
    branch,
47
 
    doc_generate,
48
 
    )
49
 
 
50
 
 
51
 
def main(argv):
52
 
    parser = OptionParser(usage="""%prog [options] OUTPUT_FORMAT
53
 
 
54
 
Available OUTPUT_FORMAT:
55
 
 
56
 
    man              man page
57
 
    rstx             man page in ReStructuredText format
58
 
    bash_completion  bash completion script""")
59
 
 
60
 
    parser.add_option("-s", "--show-filename",
61
 
                      action="store_true", dest="show_filename", default=False,
62
 
                      help="print default filename on stdout")
63
 
 
64
 
    parser.add_option("-o", "--output", dest="filename", metavar="FILE",
65
 
                      help="write output to FILE")
66
 
 
67
 
    parser.add_option("-b", "--bzr-name",
68
 
                      dest="bzr_name", default="bzr", metavar="EXEC_NAME",
69
 
                      help="name of bzr executable")
70
 
 
71
 
    parser.add_option("-e", "--examples",
72
 
                      action="callback", callback=print_extended_help,
73
 
                      help="Examples of ways to call generate_doc")
74
 
 
75
 
 
76
 
    (options, args) = parser.parse_args(argv)
77
 
 
78
 
    if len(args) != 2:
79
 
        parser.print_help()
80
 
        sys.exit(1)
81
 
 
82
 
    with bzrlib.initialize():
83
 
        commands.install_bzr_command_hooks()
84
 
        infogen_type = args[1]
85
 
        infogen_mod = doc_generate.get_module(infogen_type)
86
 
        if options.filename:
87
 
            outfilename = options.filename
88
 
        else:
89
 
            outfilename = infogen_mod.get_filename(options)
90
 
        if outfilename == "-":
91
 
            outfile = sys.stdout
92
 
        else:
93
 
            outfile = open(outfilename,"w")
94
 
        if options.show_filename and (outfilename != "-"):
95
 
            sys.stdout.write(outfilename)
96
 
            sys.stdout.write('\n')
97
 
        infogen_mod.infogen(options, outfile)
98
 
 
99
 
 
100
 
def print_extended_help(option, opt, value, parser):
101
 
    """ Program help examples
102
 
 
103
 
    Prints out the examples stored in the docstring. 
104
 
 
105
 
    """
106
 
    sys.stdout.write(__doc__ % {"prog":sys.argv[0]})
107
 
    sys.stdout.write('\n')
108
 
    sys.exit(0)
109
 
 
110
 
if __name__ == '__main__':
111
 
    main(sys.argv)