/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to generate_docs.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-04-24 10:31:28 UTC
  • mfrom: (1684.1.2 bzr.mbp.integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060424103128-a637f56a7c529bad
(mbp) tutorial improvements

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python3
 
1
#!/usr/bin/python
2
2
 
3
3
# Copyright 2005 Canonical Ltd.
4
 
#
 
4
 
5
5
# This program is free software; you can redistribute it and/or modify
6
6
# it under the terms of the GNU General Public License as published by
7
7
# the Free Software Foundation; either version 2 of the License, or
8
8
# (at your option) any later version.
9
 
#
 
9
 
10
10
# This program is distributed in the hope that it will be useful,
11
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
13
# GNU General Public License for more details.
14
 
#
 
14
 
15
15
# You should have received a copy of the GNU General Public License
16
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 brz help
20
 
 
21
 
%(prog)s creates a file with information on brz in one of
 
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
22
21
several different output formats:
23
22
 
24
23
    man              man page
25
24
    bash_completion  bash completion script
26
25
    ...
27
26
 
28
 
Examples:
 
27
Examples: 
29
28
 
30
 
    python generated-docs.py man
31
 
    python generated-docs.py bash_completion
 
29
    python2.4 generated-docs.py man
 
30
    python2.4 generated-docs.py bash_completion
32
31
 
33
32
Run "%(prog)s --help" for the option reference.
34
33
"""
35
 
import os
 
34
 
36
35
import sys
37
36
from optparse import OptionParser
38
37
 
39
 
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
40
 
 
41
 
import breezy
42
 
from breezy import (
43
 
    commands,
44
 
    doc_generate,
45
 
    )
46
 
 
 
38
import tools.doc_generate
47
39
 
48
40
def main(argv):
49
 
    parser = OptionParser(usage="""%prog [options] OUTPUT_FORMAT
50
 
 
51
 
Available OUTPUT_FORMAT:
52
 
 
53
 
    man              man page
54
 
    rstx             man page in ReStructuredText format
55
 
    bash_completion  bash completion script""")
 
41
    parser = OptionParser(usage="%prog [options] OUTPUT_FORMAT")
56
42
 
57
43
    parser.add_option("-s", "--show-filename",
58
44
                      action="store_true", dest="show_filename", default=False,
61
47
    parser.add_option("-o", "--output", dest="filename", metavar="FILE",
62
48
                      help="write output to FILE")
63
49
 
64
 
    parser.add_option("-b", "--brz-name",
65
 
                      dest="brz_name", default="brz", metavar="EXEC_NAME",
66
 
                      help="name of brz executable")
 
50
    parser.add_option("-b", "--bzr-name",
 
51
                      dest="bzr_name", default="bzr", metavar="EXEC_NAME",
 
52
                      help="name of bzr executable")
67
53
 
68
54
    parser.add_option("-e", "--examples",
69
55
                      action="callback", callback=print_extended_help,
76
62
        parser.print_help()
77
63
        sys.exit(1)
78
64
 
79
 
    with breezy.initialize():
80
 
        # Import breezy.bzr for format registration, see <http://pad.lv/956860>
81
 
        from breezy import bzr as _
82
 
        commands.install_bzr_command_hooks()
83
 
        infogen_type = args[1]
84
 
        infogen_mod = doc_generate.get_module(infogen_type)
85
 
        if options.filename:
86
 
            outfilename = options.filename
87
 
        else:
88
 
            outfilename = infogen_mod.get_filename(options)
89
 
        if outfilename == "-":
90
 
            outfile = sys.stdout
91
 
        else:
92
 
            outfile = open(outfilename, "w")
93
 
        if options.show_filename and (outfilename != "-"):
94
 
            sys.stdout.write(outfilename)
95
 
            sys.stdout.write('\n')
96
 
        infogen_mod.infogen(options, outfile)
97
 
 
 
65
    infogen_type = args[1]
 
66
    infogen_mod = tools.doc_generate.get_module(infogen_type)
 
67
 
 
68
    if options.filename:
 
69
        outfilename = options.filename
 
70
    else:
 
71
        outfilename = infogen_mod.get_filename(options)
 
72
 
 
73
    if outfilename == "-":
 
74
        outfile = sys.stdout
 
75
    else:
 
76
        outfile = open(outfilename,"w")
 
77
 
 
78
    if options.show_filename and (outfilename != "-"):
 
79
        print >>sys.stdout, outfilename
 
80
    
 
81
    infogen_mod.infogen(options, outfile)
98
82
 
99
83
def print_extended_help(option, opt, value, parser):
100
84
    """ Program help examples
101
85
 
102
 
    Prints out the examples stored in the docstring.
 
86
    Prints out the examples stored in the docstring. 
103
87
 
104
88
    """
105
 
    sys.stdout.write(__doc__ % {"prog": sys.argv[0]})
106
 
    sys.stdout.write('\n')
 
89
    print >>sys.stdout, __doc__ % {"prog":sys.argv[0]}
107
90
    sys.exit(0)
108
91
 
109
92
if __name__ == '__main__':