/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

Merged mailine

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
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
 
 
 
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
18
"""%(prog)s - generate information from built-in bzr help
20
19
 
21
20
%(prog)s creates a file with information on bzr in one of
32
31
 
33
32
Run "%(prog)s --help" for the option reference.
34
33
"""
35
 
import os
 
34
 
 
35
# Plan (devised by jblack and ndim 2005-12-10):
 
36
#   * one generate_doc.py script in top level dir right beside bzr
 
37
#   * one tools/doc_generate/ directory (python module)
 
38
#     We did not put the stuff into bzrlib because we thought
 
39
#     that all this stuff doesn't need to get loaded every time you run bzr.
 
40
#     However, I'm not sure that is actually true (ndim 2005-12-11).
 
41
#   * several generator scripts like
 
42
#           tools/doc_generate/autodoc_man_page.py
 
43
#                              autodoc_docbook_xml.py
 
44
#                              autodoc_html.py
 
45
#                              autodoc_bash_completion.py
 
46
#                              autodoc_zsh_completion.py
 
47
#   * scripts are called by running something like
 
48
#     "python2.4 generated_docs.py --man-page"         or
 
49
#     "python2.4 generated_docs.py --bash-completion"   or
 
50
#     "pytohn2.4 generated_docs.py --all"
 
51
#     
 
52
#   * one test case which iterates through all gen_*.py scripts and
 
53
#     tries to generate all the file types, checking that all generators
 
54
#     work (we'll let bzrinfogen/__init__.py provide the list to walk through)
 
55
#   * those generator scripts walk through the command and option data
 
56
#     structures to extract the required information
 
57
#   * the actual names are just prototypes and subject to change
 
58
 
 
59
 
36
60
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
 
61
import tools.doc_generate
42
62
 
43
63
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""")
 
64
    from optparse import OptionParser
 
65
    parser = OptionParser(usage="%prog [options] OUTPUT_FORMAT")
51
66
 
52
67
    parser.add_option("-s", "--show-filename",
53
68
                      action="store_true", dest="show_filename", default=False,
61
76
                      help="name of bzr executable")
62
77
 
63
78
    parser.add_option("-e", "--examples",
64
 
                      action="callback", callback=print_extended_help,
65
 
                      help="Examples of ways to call generate_doc")
 
79
                       action="callback", callback=print_extended_help,
 
80
                       help="Examples of ways to call generate_doc")
66
81
 
67
82
 
68
83
    (options, args) = parser.parse_args(argv)
71
86
        parser.print_help()
72
87
        sys.exit(1)
73
88
 
74
 
    commands.install_bzr_command_hooks()
75
 
 
76
89
    infogen_type = args[1]
77
 
    infogen_mod = doc_generate.get_module(infogen_type)
 
90
    infogen_mod = tools.doc_generate.get_module(infogen_type)
78
91
 
79
92
    if options.filename:
80
93
        outfilename = options.filename
87
100
        outfile = open(outfilename,"w")
88
101
 
89
102
    if options.show_filename and (outfilename != "-"):
90
 
        sys.stdout.write(outfilename)
91
 
        sys.stdout.write('\n')
 
103
        print >>sys.stdout, outfilename
92
104
    
93
105
    infogen_mod.infogen(options, outfile)
94
106
 
95
107
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)
 
108
        print >>sys.stdout, __doc__ % {"prog":sys.argv[0]}
 
109
        sys.exit(0)
104
110
 
105
111
if __name__ == '__main__':
106
112
    main(sys.argv)