~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/doc_generate/autodoc_man.py

  • Committer: Vincent Ladeuil
  • Date: 2011-11-24 10:47:43 UTC
  • mto: (6321.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6322.
  • Revision ID: v.ladeuil+lp@free.fr-20111124104743-rxqwhmzqu5k17f24
First cut at a working plugin to avoid conflicts in .po files by shelling out to msgmerge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
27
import time
30
28
 
33
31
import bzrlib.help_topics
34
32
import bzrlib.commands
35
33
 
36
 
from bzrlib.plugin import load_plugins
37
 
load_plugins()
38
 
 
39
34
 
40
35
def get_filename(options):
41
36
    """Provides name of manpage"""
56
51
    outfile.write(man_escape(man_head % params))
57
52
    outfile.write(man_escape(getcommand_list(params)))
58
53
    outfile.write(man_escape(getcommand_help(params)))
59
 
    outfile.write("".join(environment_variables()))
60
54
    outfile.write(man_escape(man_foot % params))
61
55
 
62
56
 
63
57
def man_escape(string):
64
58
    """Escapes strings for man page compatibility"""
65
59
    result = string.replace("\\","\\\\")
66
 
    result = result.replace("`","\\'")
67
 
    result = result.replace("'","\\*(Aq")
 
60
    result = result.replace("`","\\`")
 
61
    result = result.replace("'","\\'")
68
62
    result = result.replace("-","\\-")
69
63
    return result
70
64
 
72
66
def command_name_list():
73
67
    """Builds a list of command names from bzrlib"""
74
68
    command_names = bzrlib.commands.builtin_command_names()
75
 
    for cmdname in bzrlib.commands.plugin_command_names():
76
 
        cmd_object = bzrlib.commands.get_cmd_object(cmdname)
77
 
        if (PLUGINS_TO_DOCUMENT is None or
78
 
            cmd_object.plugin_name() in PLUGINS_TO_DOCUMENT):
79
 
            command_names.append(cmdname)
80
69
    command_names.sort()
81
70
    return command_names
82
71
 
116
105
    return output
117
106
 
118
107
 
119
 
def format_command(params, cmd):
 
108
def format_command (params, cmd):
120
109
    """Provides long help for each public command"""
121
110
    subsection_header = '.SS "%s"\n' % (cmd._usage())
122
111
    doc = "%s\n" % (cmd.__doc__)
123
112
    doc = bzrlib.help_topics.help_as_plain_text(cmd.help())
124
113
 
125
 
    # A dot at the beginning of a line is interpreted as a macro.
126
 
    # Simply join lines that begin with a dot with the previous
127
 
    # line to work around this.
128
 
    doc = doc.replace("\n.", ".")
129
 
 
130
114
    option_str = ""
131
115
    options = cmd.options()
132
116
    if options:
145
129
                    subsequent_indent=30*' ',
146
130
                    break_long_words=False,
147
131
                    )
148
 
                option_str += wrapped + '\n'
 
132
                option_str = option_str + wrapped + '\n'       
149
133
 
150
134
    aliases_str = ""
151
135
    if cmd.aliases:
172
156
    return help
173
157
 
174
158
 
175
 
def environment_variables():
176
 
    yield ".SH \"ENVIRONMENT\"\n"
177
 
 
178
 
    from bzrlib.help_topics import known_env_variables
179
 
    for k, desc in known_env_variables:
180
 
        yield ".TP\n"
181
 
        yield ".I \"%s\"\n" % k
182
 
        yield man_escape(desc) + "\n"
183
 
 
184
 
 
185
159
man_preamble = """\
186
160
.\\\"Man page for Bazaar (%(bzrcmd)s)
187
161
.\\\"
191
165
.\\\"
192
166
.\\\" Generation time: %(timestamp)s
193
167
.\\\"
194
 
 
195
 
.ie \\n(.g .ds Aq \\(aq
196
 
.el .ds Aq '
197
168
"""
198
169
 
199
170
 
226
197
"""
227
198
 
228
199
man_foot = """\
 
200
.SH "ENVIRONMENT"
 
201
.TP
 
202
.I "BZRPATH"
 
203
Path where
 
204
.B "%(bzrcmd)s"
 
205
is to look for shell plugin external commands.
 
206
.TP
 
207
.I "BZR_EMAIL"
 
208
E-Mail address of the user. Overrides default user config.
 
209
.TP
 
210
.I "EMAIL"
 
211
E-Mail address of the user. Overrides default user config.
 
212
.TP
 
213
.I "BZR_EDITOR"
 
214
Editor for editing commit messages
 
215
.TP
 
216
.I "EDITOR"
 
217
Editor for editing commit messages
 
218
.TP
 
219
.I "BZR_PLUGIN_PATH"
 
220
Paths where bzr should look for plugins
 
221
.TP
 
222
.I "BZR_HOME"
 
223
Home directory for bzr
229
224
.SH "FILES"
230
225
.TP
231
226
.I "~/.bazaar/bazaar.conf"