~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to tools/doc_generate/autodoc_rstx.py

  • Committer: Ian Clatworthy
  • Date: 2007-12-17 04:49:20 UTC
  • mfrom: (3089.3.17 bzr.ug-tweaks)
  • mto: This revision was merged to the branch mainline in revision 3120.
  • Revision ID: ian.clatworthy@internode.on.net-20071217044920-8fjh9v6m1t93c8dc
Move material out of User Guide into User Reference (Ian Clatworthy)

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
import bzrlib.help
30
30
import bzrlib.help_topics
31
31
import bzrlib.commands
 
32
import bzrlib.osutils
32
33
 
33
34
 
34
35
def get_filename(options):
46
47
             "timestamp": time.strftime("%Y-%m-%d %H:%M:%S +0000",tt),
47
48
             "version": bzrlib.__version__,
48
49
             }
 
50
    nominated_filename = getattr(options, 'filename', None)
 
51
    if nominated_filename is None:
 
52
        topic_dir = None
 
53
    else:
 
54
        topic_dir = bzrlib.osutils.dirname(nominated_filename)
49
55
    outfile.write(rstx_preamble % params)
50
56
    outfile.write(rstx_head % params)
51
 
    outfile.write(_get_body(params))
 
57
    outfile.write(_get_body(params, topic_dir))
52
58
    outfile.write(rstx_foot % params)
53
59
 
54
60
 
55
 
def _get_body(params):
 
61
def _get_body(params, topic_dir):
56
62
    """Build the manual content."""
57
63
    from bzrlib.help_topics import SECT_CONCEPT, SECT_LIST, SECT_PLUGIN
58
64
    registry = bzrlib.help_topics.topic_registry
59
65
    result = []
60
 
    result.append(_get_section(registry, SECT_CONCEPT, "Concepts"))
61
 
    result.append(_get_section(registry, SECT_LIST, "Lists"))
 
66
    result.append(_get_section(registry, SECT_CONCEPT, "Concepts",
 
67
        output_dir=topic_dir))
 
68
    result.append(_get_section(registry, SECT_LIST, "Lists",
 
69
        output_dir=topic_dir))
62
70
    result.append(_get_commands_section(registry))
63
 
    #result.append(_get_section(registry, SECT_PLUGIN, "Core Plug-ins"))
 
71
    #result.append(_get_section(registry, SECT_PLUGIN, "Standard Plug-ins"))
64
72
    return "\n".join(result)
65
73
 
66
74
 
67
 
def _get_section(registry, section, title, hdg_level1="=", hdg_level2="-"):
68
 
    """Build the manual part from topics matching that section."""
 
75
def _get_section(registry, section, title, hdg_level1="#", hdg_level2="=",
 
76
        output_dir=None):
 
77
    """Build the manual part from topics matching that section.
 
78
    
 
79
    If output_dir is not None, topics are dumped into text files there
 
80
    during processing, as well as being included in the return result.
 
81
    """
69
82
    topics = sorted(registry.get_topics_for_section(section))
70
83
    lines = [title, hdg_level1 * len(title), ""]
71
84
 
86
99
        help = registry.get_detail(topic)
87
100
        heading,text = help.split("\n", 1)
88
101
        lines.append(heading)
89
 
        lines.append(hdg_level2 * len(heading))
 
102
        if not text.startswith(hdg_level2):
 
103
            lines.append(hdg_level2 * len(heading))
90
104
        lines.append(text)
91
105
        lines.append('')
92
106
        # check that topic match heading
93
107
        if topic != heading.lower():
94
108
            links_glue.append((topic, heading))
 
109
        # dump the text if requested
 
110
        if output_dir is not None:
 
111
            out_file = bzrlib.osutils.pathjoin(output_dir, topic + ".txt")
 
112
            _dump_text(out_file, help)
95
113
 
96
114
    # provide links glue for topics that don't match headings
97
115
    lines.extend([".. _%s: `%s`_" % i for i in links_glue])
100
118
    return "\n" + "\n".join(lines) + "\n"
101
119
 
102
120
 
103
 
def _get_commands_section(registry, title="Commands", hdg_level1="=",
104
 
                          hdg_level2="-"):
 
121
def _dump_text(filename, text):
 
122
    """Dump text to filename."""
 
123
    f =  open(filename, "w")
 
124
    f.writelines(text)
 
125
    f.close()
 
126
 
 
127
 
 
128
def _get_commands_section(registry, title="Commands", hdg_level1="#",
 
129
                          hdg_level2="="):
105
130
    """Build the comands reference section of the manual."""
106
131
    lines = [title, hdg_level1 * len(title), ""]
107
132
    cmds = sorted(bzrlib.commands.builtin_command_names())
132
157
 
133
158
 
134
159
rstx_head = """\
135
 
=====================
 
160
#####################
136
161
Bazaar User Reference
137
 
=====================
 
162
#####################
138
163
 
139
164
:Version:   %(version)s
140
165
:Generated: %(datestamp)s
144
169
-----
145
170
 
146
171
About This Manual
147
 
=================
 
172
#################
148
173
 
149
174
This manual is generated from Bazaar's online help. To use
150
175
the online help system, try the following commands.