46
47
"timestamp": time.strftime("%Y-%m-%d %H:%M:%S +0000",tt),
47
48
"version": bzrlib.__version__,
50
nominated_filename = options.filename
51
if nominated_filename is None:
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)
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
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)
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="=",
77
"""Build the manual part from topics matching that section.
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.
69
82
topics = sorted(registry.get_topics_for_section(section))
70
83
lines = [title, hdg_level1 * len(title), ""]
93
106
# check that topic match heading
94
107
if topic != heading.lower():
95
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)
97
114
# provide links glue for topics that don't match headings
98
115
lines.extend([".. _%s: `%s`_" % i for i in links_glue])
101
118
return "\n" + "\n".join(lines) + "\n"
121
def _dump_text(filename, text):
122
"""Dump text to filename."""
123
f = open(filename, "w")
104
128
def _get_commands_section(registry, title="Commands", hdg_level1="#",
106
130
"""Build the comands reference section of the manual."""