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
17
"""man.py - create man page from built-in bzr help and static text
17
"""man.py - create man page from built-in brz help and static text
20
* use usage information instead of simple "bzr foo" in COMMAND OVERVIEW
20
* use usage information instead of simple "brz foo" in COMMAND OVERVIEW
21
21
* add command aliases
24
PLUGINS_TO_DOCUMENT = ["launchpad"]
31
import bzrlib.help_topics
32
import bzrlib.commands
30
import breezy.help_topics
31
import breezy.commands
32
from breezy.doc_generate import get_autodoc_datetime
34
from breezy.plugin import load_plugins
35
38
def get_filename(options):
36
39
"""Provides name of manpage"""
37
return "%s.1" % (options.bzr_name)
40
return "%s.1" % (options.brz_name)
40
43
def infogen(options, outfile):
41
44
"""Assembles a man page"""
45
d = get_autodoc_datetime()
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__,
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__,
50
52
outfile.write(man_preamble % params)
51
53
outfile.write(man_escape(man_head % params))
52
54
outfile.write(man_escape(getcommand_list(params)))
53
55
outfile.write(man_escape(getcommand_help(params)))
56
outfile.write("".join(environment_variables()))
54
57
outfile.write(man_escape(man_foot % params))
57
60
def man_escape(string):
58
61
"""Escapes strings for man page compatibility"""
59
result = string.replace("\\","\\\\")
60
result = result.replace("`","\\`")
61
result = result.replace("'","\\'")
62
result = result.replace("-","\\-")
62
result = string.replace("\\", "\\\\")
63
result = result.replace("`", "\\'")
64
result = result.replace("'", "\\*(Aq")
65
result = result.replace("-", "\\-")
66
69
def command_name_list():
67
"""Builds a list of command names from bzrlib"""
68
command_names = bzrlib.commands.builtin_command_names()
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)
69
77
command_names.sort()
70
78
return command_names
73
def getcommand_list (params):
81
def getcommand_list(params):
74
82
"""Builds summary help for command names in manpage format"""
75
bzrcmd = params["bzrcmd"]
83
brzcmd = params["brzcmd"]
76
84
output = '.SH "COMMAND OVERVIEW"\n'
77
85
for cmd_name in command_name_list():
78
cmd_object = bzrlib.commands.get_cmd_object(cmd_name)
86
cmd_object = breezy.commands.get_cmd_object(cmd_name)
79
87
if cmd_object.hidden:
81
89
cmd_help = cmd_object.help()
85
93
tmp = '.TP\n.B "%s"\n%s\n' % (usage, firstline)
86
94
output = output + tmp
88
raise RuntimeError, "Command '%s' has no help text" % (cmd_name)
96
raise RuntimeError("Command '%s' has no help text" % (cmd_name))
92
100
def getcommand_help(params):
93
"""Shows individual options for a bzr command"""
94
output='.SH "COMMAND REFERENCE"\n'
101
"""Shows individual options for a brz command"""
102
output = '.SH "COMMAND REFERENCE"\n'
96
104
for cmd_name in command_name_list():
97
cmd_object = bzrlib.commands.get_cmd_object(cmd_name)
105
cmd_object = breezy.commands.get_cmd_object(cmd_name)
98
106
if cmd_object.hidden:
100
108
formatted[cmd_name] = format_command(params, cmd_object)
108
def format_command (params, cmd):
116
def format_command(params, cmd):
109
117
"""Provides long help for each public command"""
110
118
subsection_header = '.SS "%s"\n' % (cmd._usage())
111
119
doc = "%s\n" % (cmd.__doc__)
112
doc = bzrlib.help_topics.help_as_plain_text(cmd.help())
120
doc = breezy.help_topics.help_as_plain_text(cmd.help())
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.", ".")
115
128
options = cmd.options()
153
166
def format_alias(params, alias, cmd_name):
154
help = '.SS "bzr %s"\n' % alias
155
help += 'Alias for "%s", see "bzr %s".\n' % (cmd_name, cmd_name)
167
help = '.SS "brz %s"\n' % alias
168
help += 'Alias for "%s", see "brz %s".\n' % (cmd_name, cmd_name)
172
def environment_variables():
173
yield ".SH \"ENVIRONMENT\"\n"
175
from breezy.help_topics import known_env_variables
176
for k, desc in known_env_variables:
178
yield ".I \"%s\"\n" % k
179
yield man_escape(desc) + "\n"
159
182
man_preamble = """\
160
.\\\"Man page for Bazaar (%(bzrcmd)s)
183
.\\\"Man page for Breezy (%(brzcmd)s)
162
185
.\\\" Large parts of this file are autogenerated from the output of
163
.\\\" \"%(bzrcmd)s help commands\"
164
.\\\" \"%(bzrcmd)s help <cmd>\"
166
.\\\" Generation time: %(timestamp)s
186
.\\\" \"%(brzcmd)s help commands\"
187
.\\\" \"%(brzcmd)s help <cmd>\"
190
.ie \\n(.g .ds Aq \\(aq
172
.TH bzr 1 "%(datestamp)s" "%(version)s" "Bazaar"
196
.TH brz 1 "%(datestamp)s" "%(version)s" "Breezy"
174
%(bzrcmd)s - Bazaar next-generation distributed version control
198
%(brzcmd)s - Breezy next-generation distributed version control
179
203
.I "command_options"
188
212
.SH "DESCRIPTION"
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.
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.
217
Breezy keeps track of changes to software source code (or similar information);
218
lets you explore who changed it, when, and why; merges concurrent changes; and
219
helps people work together in a team.
201
is to look for shell plugin external commands.
204
E-Mail address of the user. Overrides default user config.
207
E-Mail address of the user. Overrides default user config.
210
Editor for editing commit messages
213
Editor for editing commit messages
216
Paths where bzr should look for plugins
219
Home directory for bzr
222
.I "~/.bazaar/bazaar.conf"
225
.I "~/.config/breezy/breezy.conf"
223
226
Contains the user's default configuration. The section
225
228
is used to define general configuration that will be applied everywhere.