/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: Jelmer Vernooij
  • Date: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

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