/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_rstx.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:
17
17
"""Generate reStructuredText source for the User Reference Manual.
18
18
Loosely based on the manpage generator autodoc_man.py.
19
19
 
20
 
Written by the Bazaar community.
 
20
Written by the Bazaar/Breezy community.
21
21
"""
22
22
 
23
 
from __future__ import absolute_import
24
 
 
25
23
import time
26
24
 
27
 
import bzrlib
28
 
import bzrlib.help
29
 
import bzrlib.help_topics
30
 
import bzrlib.commands
31
 
import bzrlib.osutils
 
25
import breezy
 
26
import breezy.help
 
27
import breezy.help_topics
 
28
import breezy.commands
 
29
import breezy.osutils
32
30
 
33
31
 
34
32
def get_filename(options):
35
33
    """Provides name of manual"""
36
 
    return "%s_man.txt" % (options.bzr_name)
 
34
    return "%s_man.txt" % (options.brz_name)
37
35
 
38
36
 
39
37
def infogen(options, outfile):
41
39
    t = time.time()
42
40
    tt = time.gmtime(t)
43
41
    params = \
44
 
           { "bzrcmd": options.bzr_name,
45
 
             "datestamp": time.strftime("%Y-%m-%d",tt),
46
 
             "timestamp": time.strftime("%Y-%m-%d %H:%M:%S +0000",tt),
47
 
             "version": bzrlib.__version__,
48
 
             }
 
42
        {"brzcmd": options.brz_name,
 
43
         "datestamp": time.strftime("%Y-%m-%d", tt),
 
44
         "timestamp": time.strftime("%Y-%m-%d %H:%M:%S +0000", tt),
 
45
         "version": breezy.__version__,
 
46
         }
49
47
    nominated_filename = getattr(options, 'filename', None)
50
48
    if nominated_filename is None:
51
49
        topic_dir = None
52
50
    else:
53
 
        topic_dir = bzrlib.osutils.dirname(nominated_filename)
 
51
        topic_dir = breezy.osutils.dirname(nominated_filename)
54
52
    outfile.write(rstx_preamble % params)
55
53
    outfile.write(rstx_head % params)
56
54
    outfile.write(_get_body(params, topic_dir))
59
57
 
60
58
def _get_body(params, topic_dir):
61
59
    """Build the manual content."""
62
 
    from bzrlib.help_topics import SECT_CONCEPT, SECT_LIST, SECT_PLUGIN
63
 
    registry = bzrlib.help_topics.topic_registry
 
60
    from breezy.help_topics import SECT_CONCEPT, SECT_LIST, SECT_PLUGIN
 
61
    registry = breezy.help_topics.topic_registry
64
62
    result = []
65
63
    result.append(_get_section(registry, SECT_CONCEPT, "Concepts",
66
 
        output_dir=topic_dir))
 
64
                               output_dir=topic_dir))
67
65
    result.append(_get_section(registry, SECT_LIST, "Lists",
68
 
        output_dir=topic_dir))
 
66
                               output_dir=topic_dir))
69
67
    result.append(_get_commands_section(registry, output_dir=topic_dir))
70
68
    return "\n".join(result)
71
69
 
72
70
 
73
71
def _get_section(registry, section, title, hdg_level1="#", hdg_level2="=",
74
 
        output_dir=None):
 
72
                 output_dir=None):
75
73
    """Build the manual part from topics matching that section.
76
 
    
 
74
 
77
75
    If output_dir is not None, topics are dumped into text files there
78
76
    during processing, as well as being included in the return result.
79
77
    """
101
99
 
102
100
 
103
101
def _get_commands_section(registry, title="Commands", hdg_level1="#",
104
 
        hdg_level2="=", output_dir=None):
 
102
                          hdg_level2="=", output_dir=None):
105
103
    """Build the commands reference section of the manual."""
106
104
    file_per_topic = output_dir is not None
107
105
    lines = [title, hdg_level1 * len(title), ""]
108
106
    if file_per_topic:
109
107
        lines.extend([".. toctree::", "   :maxdepth: 1", ""])
110
108
 
111
 
    cmds = sorted(bzrlib.commands.builtin_command_names())
 
109
    cmds = sorted(breezy.commands.builtin_command_names())
112
110
    for cmd_name in cmds:
113
 
        cmd_object = bzrlib.commands.get_cmd_object(cmd_name)
 
111
        cmd_object = breezy.commands.get_cmd_object(cmd_name)
114
112
        if cmd_object.hidden:
115
113
            continue
116
114
        heading = cmd_name
129
127
def _dump_text(output_dir, topic, text):
130
128
    """Dump text for a topic to a file."""
131
129
    topic_id = "%s-%s" % (topic, "help")
132
 
    filename = bzrlib.osutils.pathjoin(output_dir, topic_id + ".txt")
133
 
    f =  open(filename, "w")
134
 
    f.write(text.encode('utf-8'))
135
 
    f.close()
 
130
    filename = breezy.osutils.pathjoin(output_dir, topic_id + ".txt")
 
131
    with open(filename, "wb") as f:
 
132
        f.write(text.encode('utf-8'))
136
133
    return topic_id
137
134
 
138
135
 
140
137
# TEMPLATES
141
138
 
142
139
rstx_preamble = """.. This file is autogenerated from the output of
143
 
..     %(bzrcmd)s help topics
144
 
..     %(bzrcmd)s help commands
145
 
..     %(bzrcmd)s help <cmd>
 
140
..     %(brzcmd)s help topics
 
141
..     %(brzcmd)s help commands
 
142
..     %(brzcmd)s help <cmd>
146
143
..
147
144
 
148
145
"""
150
147
 
151
148
rstx_head = """\
152
149
#####################
153
 
Bazaar User Reference
 
150
Breezy User Reference
154
151
#####################
155
152
 
156
153
About This Manual
157
154
#################
158
155
 
159
 
This manual is generated from Bazaar's online help. To use
 
156
This manual is generated from Breezy's online help. To use
160
157
the online help system, try the following commands.
161
158
 
162
159
    Introduction including a list of commonly used commands::
163
160
 
164
 
        bzr help
 
161
        brz help
165
162
 
166
163
    List of topics and a summary of each::
167
164
 
168
 
        bzr help topics
 
165
        brz help topics
169
166
 
170
167
    List of commands and a summary of each::
171
168
 
172
 
        bzr help commands
 
169
        brz help commands
173
170
 
174
171
    More information about a particular topic or command::
175
172
 
176
 
        bzr help topic-or-command-name
177
 
 
178
 
The following web sites provide further information on Bazaar:
179
 
 
180
 
:Home page:                     http://bazaar.canonical.com/
181
 
:Official docs:                 http://doc.bazaar.canonical.com/
182
 
:Launchpad:                     https://launchpad.net/bzr/
 
173
        brz help topic-or-command-name
 
174
 
 
175
The following web sites provide further information on Breezy:
 
176
 
 
177
:Home page:                     http://www.breezy-vcs.org/
 
178
:Breezy docs:                   http://www.breezy-vcs.org/doc/
 
179
:Launchpad:                     https://launchpad.net/brz/
183
180
"""
184
181
 
185
182