/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: 2012-01-18 14:09:19 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120118140919-rlvdrhpc0nq1lbwi
Change set/remove to require a lock for the branch config files.

This means that tests (or any plugin for that matter) do not requires an
explicit lock on the branch anymore to change a single option. This also
means the optimisation becomes "opt-in" and as such won't be as
spectacular as it may be and/or harder to get right (nothing fails
anymore).

This reduces the diff by ~300 lines.

Code/tests that were updating more than one config option is still taking
a lock to at least avoid some IOs and demonstrate the benefits through
the decreased number of hpss calls.

The duplication between BranchStack and BranchOnlyStack will be removed
once the same sharing is in place for local config files, at which point
the Stack class itself may be able to host the changes.

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