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