/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 bzrlib/doc_generate/autodoc_man.py

  • Committer: Robert Collins
  • Date: 2010-05-05 00:05:29 UTC
  • mto: This revision was merged to the branch mainline in revision 5206.
  • Revision ID: robertc@robertcollins.net-20100505000529-ltmllyms5watqj5u
Make 'pydoc bzrlib.tests.build_tree_shape' useful.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""man.py - create man page from built-in brz help and static text
 
17
"""man.py - create man page from built-in bzr help and static text
18
18
 
19
19
TODO:
20
 
  * use usage information instead of simple "brz foo" in COMMAND OVERVIEW
 
20
  * use usage information instead of simple "bzr foo" in COMMAND OVERVIEW
21
21
  * add command aliases
22
22
"""
23
23
 
24
 
from __future__ import absolute_import
25
 
 
26
 
PLUGINS_TO_DOCUMENT = ["launchpad"]
27
 
 
 
24
import os
 
25
import sys
28
26
import textwrap
29
 
 
30
 
import breezy
31
 
import breezy.help
32
 
import breezy.help_topics
33
 
import breezy.commands
34
 
from breezy.doc_generate import get_autodoc_datetime
35
 
 
36
 
from breezy.plugin import load_plugins
37
 
load_plugins()
 
27
import time
 
28
 
 
29
import bzrlib
 
30
import bzrlib.help
 
31
import bzrlib.help_topics
 
32
import bzrlib.commands
38
33
 
39
34
 
40
35
def get_filename(options):
41
36
    """Provides name of manpage"""
42
 
    return "%s.1" % (options.brz_name)
 
37
    return "%s.1" % (options.bzr_name)
43
38
 
44
39
 
45
40
def infogen(options, outfile):
46
41
    """Assembles a man page"""
47
 
    d = get_autodoc_datetime()
 
42
    t = time.time()
 
43
    tt = time.gmtime(t)
48
44
    params = \
49
 
        {"brzcmd": options.brz_name,
50
 
         "datestamp": d.strftime("%Y-%m-%d"),
51
 
         "timestamp": d.strftime("%Y-%m-%d %H:%M:%S +0000"),
52
 
         "version": breezy.__version__,
53
 
         }
 
45
           { "bzrcmd": options.bzr_name,
 
46
             "datestamp": time.strftime("%Y-%m-%d",tt),
 
47
             "timestamp": time.strftime("%Y-%m-%d %H:%M:%S +0000",tt),
 
48
             "version": bzrlib.__version__,
 
49
             }
54
50
    outfile.write(man_preamble % params)
55
51
    outfile.write(man_escape(man_head % params))
56
52
    outfile.write(man_escape(getcommand_list(params)))
57
53
    outfile.write(man_escape(getcommand_help(params)))
58
 
    outfile.write("".join(environment_variables()))
59
54
    outfile.write(man_escape(man_foot % params))
60
55
 
61
56
 
62
57
def man_escape(string):
63
58
    """Escapes strings for man page compatibility"""
64
 
    result = string.replace("\\", "\\\\")
65
 
    result = result.replace("`", "\\'")
66
 
    result = result.replace("'", "\\*(Aq")
67
 
    result = result.replace("-", "\\-")
 
59
    result = string.replace("\\","\\\\")
 
60
    result = result.replace("`","\\`")
 
61
    result = result.replace("'","\\'")
 
62
    result = result.replace("-","\\-")
68
63
    return result
69
64
 
70
65
 
71
66
def command_name_list():
72
 
    """Builds a list of command names from breezy"""
73
 
    command_names = breezy.commands.builtin_command_names()
74
 
    for cmdname in breezy.commands.plugin_command_names():
75
 
        cmd_object = breezy.commands.get_cmd_object(cmdname)
76
 
        if (PLUGINS_TO_DOCUMENT is None or
77
 
                cmd_object.plugin_name() in PLUGINS_TO_DOCUMENT):
78
 
            command_names.append(cmdname)
 
67
    """Builds a list of command names from bzrlib"""
 
68
    command_names = bzrlib.commands.builtin_command_names()
79
69
    command_names.sort()
80
70
    return command_names
81
71
 
82
72
 
83
 
def getcommand_list(params):
 
73
def getcommand_list (params):
84
74
    """Builds summary help for command names in manpage format"""
85
 
    brzcmd = params["brzcmd"]
 
75
    bzrcmd = params["bzrcmd"]
86
76
    output = '.SH "COMMAND OVERVIEW"\n'
87
77
    for cmd_name in command_name_list():
88
 
        cmd_object = breezy.commands.get_cmd_object(cmd_name)
 
78
        cmd_object = bzrlib.commands.get_cmd_object(cmd_name)
89
79
        if cmd_object.hidden:
90
80
            continue
91
81
        cmd_help = cmd_object.help()
95
85
            tmp = '.TP\n.B "%s"\n%s\n' % (usage, firstline)
96
86
            output = output + tmp
97
87
        else:
98
 
            raise RuntimeError("Command '%s' has no help text" % (cmd_name))
 
88
            raise RuntimeError, "Command '%s' has no help text" % (cmd_name)
99
89
    return output
100
90
 
101
91
 
102
92
def getcommand_help(params):
103
 
    """Shows individual options for a brz command"""
104
 
    output = '.SH "COMMAND REFERENCE"\n'
 
93
    """Shows individual options for a bzr command"""
 
94
    output='.SH "COMMAND REFERENCE"\n'
105
95
    formatted = {}
106
96
    for cmd_name in command_name_list():
107
 
        cmd_object = breezy.commands.get_cmd_object(cmd_name)
 
97
        cmd_object = bzrlib.commands.get_cmd_object(cmd_name)
108
98
        if cmd_object.hidden:
109
99
            continue
110
100
        formatted[cmd_name] = format_command(params, cmd_object)
115
105
    return output
116
106
 
117
107
 
118
 
def format_command(params, cmd):
 
108
def format_command (params, cmd):
119
109
    """Provides long help for each public command"""
120
110
    subsection_header = '.SS "%s"\n' % (cmd._usage())
121
111
    doc = "%s\n" % (cmd.__doc__)
122
 
    doc = breezy.help_topics.help_as_plain_text(cmd.help())
123
 
 
124
 
    # A dot at the beginning of a line is interpreted as a macro.
125
 
    # Simply join lines that begin with a dot with the previous
126
 
    # line to work around this.
127
 
    doc = doc.replace("\n.", ".")
 
112
    doc = bzrlib.help_topics.help_as_plain_text(cmd.help())
128
113
 
129
114
    option_str = ""
130
115
    options = cmd.options()
141
126
                    l += ', -' + short_name
142
127
                l += (30 - len(l)) * ' ' + (help or '')
143
128
                wrapped = textwrap.fill(l, initial_indent='',
144
 
                                        subsequent_indent=30 * ' ',
145
 
                                        break_long_words=False,
146
 
                                        )
147
 
                option_str += wrapped + '\n'
 
129
                    subsequent_indent=30*' ',
 
130
                    break_long_words=False,
 
131
                    )
 
132
                option_str = option_str + wrapped + '\n'       
148
133
 
149
134
    aliases_str = ""
150
135
    if cmd.aliases:
166
151
 
167
152
 
168
153
def format_alias(params, alias, cmd_name):
169
 
    help = '.SS "brz %s"\n' % alias
170
 
    help += 'Alias for "%s", see "brz %s".\n' % (cmd_name, cmd_name)
 
154
    help = '.SS "bzr %s"\n' % alias
 
155
    help += 'Alias for "%s", see "bzr %s".\n' % (cmd_name, cmd_name)
171
156
    return help
172
157
 
173
158
 
174
 
def environment_variables():
175
 
    yield ".SH \"ENVIRONMENT\"\n"
176
 
 
177
 
    from breezy.help_topics import known_env_variables
178
 
    for k, desc in known_env_variables:
179
 
        yield ".TP\n"
180
 
        yield ".I \"%s\"\n" % k
181
 
        yield man_escape(desc) + "\n"
182
 
 
183
 
 
184
159
man_preamble = """\
185
 
.\\\"Man page for Breezy (%(brzcmd)s)
 
160
.\\\"Man page for Bazaar (%(bzrcmd)s)
186
161
.\\\"
187
162
.\\\" Large parts of this file are autogenerated from the output of
188
 
.\\\"     \"%(brzcmd)s help commands\"
189
 
.\\\"     \"%(brzcmd)s help <cmd>\"
190
 
.\\\"
191
 
 
192
 
.ie \\n(.g .ds Aq \\(aq
193
 
.el .ds Aq '
 
163
.\\\"     \"%(bzrcmd)s help commands\"
 
164
.\\\"     \"%(bzrcmd)s help <cmd>\"
 
165
.\\\"
 
166
.\\\" Generation time: %(timestamp)s
 
167
.\\\"
194
168
"""
195
169
 
196
170
 
197
171
man_head = """\
198
 
.TH brz 1 "%(datestamp)s" "%(version)s" "Breezy"
 
172
.TH bzr 1 "%(datestamp)s" "%(version)s" "Bazaar"
199
173
.SH "NAME"
200
 
%(brzcmd)s - Breezy next-generation distributed version control
 
174
%(bzrcmd)s - Bazaar next-generation distributed version control
201
175
.SH "SYNOPSIS"
202
 
.B "%(brzcmd)s"
 
176
.B "%(bzrcmd)s"
203
177
.I "command"
204
178
[
205
179
.I "command_options"
206
180
]
207
181
.br
208
 
.B "%(brzcmd)s"
 
182
.B "%(bzrcmd)s"
209
183
.B "help"
210
184
.br
211
 
.B "%(brzcmd)s"
 
185
.B "%(bzrcmd)s"
212
186
.B "help"
213
187
.I "command"
214
188
.SH "DESCRIPTION"
215
 
 
216
 
Breezy (or %(brzcmd)s) is a distributed version control system that is powerful,
217
 
friendly, and scalable.  Breezy is a fork of the Bazaar version control system.
218
 
 
219
 
Breezy keeps track of changes to software source code (or similar information);
220
 
lets you explore who changed it, when, and why; merges concurrent changes; and
221
 
helps people work together in a team.
 
189
Bazaar (or %(bzrcmd)s) is a project of Canonical to develop an open source
 
190
distributed version control system that is powerful, friendly, and scalable.
 
191
Version control means a system that keeps track of previous revisions
 
192
of software source code or similar information and helps people work on it in teams.
222
193
"""
223
194
 
224
195
man_foot = """\
 
196
.SH "ENVIRONMENT"
 
197
.TP
 
198
.I "BZRPATH"
 
199
Path where
 
200
.B "%(bzrcmd)s"
 
201
is to look for shell plugin external commands.
 
202
.TP
 
203
.I "BZR_EMAIL"
 
204
E-Mail address of the user. Overrides default user config.
 
205
.TP
 
206
.I "EMAIL"
 
207
E-Mail address of the user. Overrides default user config.
 
208
.TP
 
209
.I "BZR_EDITOR"
 
210
Editor for editing commit messages
 
211
.TP
 
212
.I "EDITOR"
 
213
Editor for editing commit messages
 
214
.TP
 
215
.I "BZR_PLUGIN_PATH"
 
216
Paths where bzr should look for plugins
 
217
.TP
 
218
.I "BZR_HOME"
 
219
Home directory for bzr
225
220
.SH "FILES"
226
221
.TP
227
 
.I "~/.config/breezy/breezy.conf"
 
222
.I "~/.bazaar/bazaar.conf"
228
223
Contains the user's default configuration. The section
229
224
.B [DEFAULT]
230
225
is used to define general configuration that will be applied everywhere.
246
241
.br
247
242
log10 = log --short -r -10..-1
248
243
.SH "SEE ALSO"
249
 
.UR https://www.breezy-vcs.org/
250
 
.BR https://www.breezy-vcs.org/
 
244
.UR http://www.bazaar.canonical.com/
 
245
.BR http://www.bazaar.canonical.com/
251
246
"""
 
247