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

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

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