~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/doc_generate/autodoc_rstx.py

  • Committer: John Arbash Meinel
  • Date: 2009-08-25 18:45:40 UTC
  • mto: (4634.6.15 2.0)
  • mto: This revision was merged to the branch mainline in revision 4667.
  • Revision ID: john@arbash-meinel.com-20090825184540-6dn3xjq62xhgj2gq
Add support for skipping ghost nodes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2006-2007 Canonical Ltd.
 
1
# Copyright (C) 2006-2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Generate ReStructuredText source for the User Reference Manual.
18
18
Loosely based on the manpage generator autodoc_man.py.
22
22
 
23
23
import os
24
24
import sys
25
 
import textwrap
26
25
import time
27
26
 
28
27
import bzrlib
29
28
import bzrlib.help
30
29
import bzrlib.help_topics
31
30
import bzrlib.commands
 
31
import bzrlib.osutils
32
32
 
33
33
 
34
34
def get_filename(options):
46
46
             "timestamp": time.strftime("%Y-%m-%d %H:%M:%S +0000",tt),
47
47
             "version": bzrlib.__version__,
48
48
             }
 
49
    nominated_filename = getattr(options, 'filename', None)
 
50
    if nominated_filename is None:
 
51
        topic_dir = None
 
52
    else:
 
53
        topic_dir = bzrlib.osutils.dirname(nominated_filename)
49
54
    outfile.write(rstx_preamble % params)
50
55
    outfile.write(rstx_head % params)
51
 
    outfile.write(_get_body(params))
 
56
    outfile.write(_get_body(params, topic_dir))
52
57
    outfile.write(rstx_foot % params)
53
58
 
54
59
 
55
 
def _get_body(params):
 
60
def _get_body(params, topic_dir):
56
61
    """Build the manual content."""
57
62
    from bzrlib.help_topics import SECT_CONCEPT, SECT_LIST, SECT_PLUGIN
58
63
    registry = bzrlib.help_topics.topic_registry
59
64
    result = []
60
 
    result.append(_get_section(registry, SECT_CONCEPT, "Concepts"))
61
 
    result.append(_get_section(registry, SECT_LIST, "Lists"))
 
65
    result.append(_get_section(registry, SECT_CONCEPT, "Concepts",
 
66
        output_dir=topic_dir))
 
67
    result.append(_get_section(registry, SECT_LIST, "Lists",
 
68
        output_dir=topic_dir))
62
69
    result.append(_get_commands_section(registry))
63
 
    #result.append(_get_section(registry, SECT_PLUGIN, "Core Plug-ins"))
 
70
    #result.append(_get_section(registry, SECT_PLUGIN, "Standard Plug-ins"))
64
71
    return "\n".join(result)
65
72
 
66
73
 
67
 
def _get_section(registry, section, title, hdg_level1="=", hdg_level2="-"):
68
 
    """Build the manual part from topics matching that section."""
 
74
def _get_section(registry, section, title, hdg_level1="#", hdg_level2="=",
 
75
        output_dir=None):
 
76
    """Build the manual part from topics matching that section.
 
77
    
 
78
    If output_dir is not None, topics are dumped into text files there
 
79
    during processing, as well as being included in the return result.
 
80
    """
69
81
    topics = sorted(registry.get_topics_for_section(section))
70
82
    lines = [title, hdg_level1 * len(title), ""]
71
83
 
86
98
        help = registry.get_detail(topic)
87
99
        heading,text = help.split("\n", 1)
88
100
        lines.append(heading)
89
 
        lines.append(hdg_level2 * len(heading))
 
101
        if not text.startswith(hdg_level2):
 
102
            lines.append(hdg_level2 * len(heading))
90
103
        lines.append(text)
91
104
        lines.append('')
92
105
        # check that topic match heading
93
106
        if topic != heading.lower():
94
107
            links_glue.append((topic, heading))
 
108
        # dump the text if requested
 
109
        if output_dir is not None:
 
110
            out_file = bzrlib.osutils.pathjoin(output_dir, topic + ".txt")
 
111
            _dump_text(out_file, help)
95
112
 
96
113
    # provide links glue for topics that don't match headings
97
114
    lines.extend([".. _%s: `%s`_" % i for i in links_glue])
100
117
    return "\n" + "\n".join(lines) + "\n"
101
118
 
102
119
 
103
 
def _get_commands_section(registry, title="Commands", hdg_level1="=",
104
 
                          hdg_level2="-"):
105
 
    """Build the comands reference section of the manual."""
 
120
def _dump_text(filename, text):
 
121
    """Dump text to filename."""
 
122
    f =  open(filename, "w")
 
123
    f.writelines(text)
 
124
    f.close()
 
125
 
 
126
 
 
127
def _get_commands_section(registry, title="Commands", hdg_level1="#",
 
128
                          hdg_level2="="):
 
129
    """Build the commands reference section of the manual."""
106
130
    lines = [title, hdg_level1 * len(title), ""]
107
131
    cmds = sorted(bzrlib.commands.builtin_command_names())
108
132
    for cmd_name in cmds:
132
156
 
133
157
 
134
158
rstx_head = """\
135
 
=====================
 
159
#####################
136
160
Bazaar User Reference
137
 
=====================
 
161
#####################
138
162
 
139
163
:Version:   %(version)s
140
164
:Generated: %(datestamp)s
141
165
 
142
 
.. contents::
 
166
.. contents:: :depth: 3
143
167
 
144
168
-----
145
169
 
146
170
About This Manual
147
 
=================
 
171
#################
148
172
 
149
173
This manual is generated from Bazaar's online help. To use
150
174
the online help system, try the following commands.