/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 tools/generate_docs.py

  • Committer: Vincent Ladeuil
  • Date: 2010-01-25 15:55:48 UTC
  • mto: (4985.1.4 add-attr-cleanup)
  • mto: This revision was merged to the branch mainline in revision 4988.
  • Revision ID: v.ladeuil+lp@free.fr-20100125155548-0l352pujvt5bzl5e
Deploy addAttrCleanup on the whole test suite.

Several use case worth mentioning:

- setting a module or any other object attribute is the majority
by far. In some cases the setting itself is deferred but most of
the time we want to set at the same time we add the cleanup.

- there multiple occurrences of protecting hooks or ui factory
which are now useless (the test framework takes care of that now),

- there was some lambda uses that can now be avoided.

That first cleanup already simplifies things a lot.

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
from bzrlib import commands, doc_generate
 
42
 
 
43
def main(argv):
 
44
    parser = OptionParser(usage="""%prog [options] OUTPUT_FORMAT
 
45
 
 
46
Available OUTPUT_FORMAT:
 
47
 
 
48
    man              man page
 
49
    rstx             man page in ReStructuredText format
 
50
    bash_completion  bash completion script""")
 
51
 
 
52
    parser.add_option("-s", "--show-filename",
 
53
                      action="store_true", dest="show_filename", default=False,
 
54
                      help="print default filename on stdout")
 
55
 
 
56
    parser.add_option("-o", "--output", dest="filename", metavar="FILE",
 
57
                      help="write output to FILE")
 
58
 
 
59
    parser.add_option("-b", "--bzr-name",
 
60
                      dest="bzr_name", default="bzr", metavar="EXEC_NAME",
 
61
                      help="name of bzr executable")
 
62
 
 
63
    parser.add_option("-e", "--examples",
 
64
                      action="callback", callback=print_extended_help,
 
65
                      help="Examples of ways to call generate_doc")
 
66
 
 
67
 
 
68
    (options, args) = parser.parse_args(argv)
 
69
 
 
70
    if len(args) != 2:
 
71
        parser.print_help()
 
72
        sys.exit(1)
 
73
 
 
74
    commands.install_bzr_command_hooks()
 
75
 
 
76
    infogen_type = args[1]
 
77
    infogen_mod = doc_generate.get_module(infogen_type)
 
78
 
 
79
    if options.filename:
 
80
        outfilename = options.filename
 
81
    else:
 
82
        outfilename = infogen_mod.get_filename(options)
 
83
 
 
84
    if outfilename == "-":
 
85
        outfile = sys.stdout
 
86
    else:
 
87
        outfile = open(outfilename,"w")
 
88
 
 
89
    if options.show_filename and (outfilename != "-"):
 
90
        sys.stdout.write(outfilename)
 
91
        sys.stdout.write('\n')
 
92
    
 
93
    infogen_mod.infogen(options, outfile)
 
94
 
 
95
def print_extended_help(option, opt, value, parser):
 
96
    """ Program help examples
 
97
 
 
98
    Prints out the examples stored in the docstring. 
 
99
 
 
100
    """
 
101
    sys.stdout.write(__doc__ % {"prog":sys.argv[0]})
 
102
    sys.stdout.write('\n')
 
103
    sys.exit(0)
 
104
 
 
105
if __name__ == '__main__':
 
106
    main(sys.argv)