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

  • Committer: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

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