46
47
"timestamp": time.strftime("%Y-%m-%d %H:%M:%S +0000",tt),
47
48
"version": bzrlib.__version__,
50
nominated_filename = getattr(options, 'filename', None)
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), ""]
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)
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)
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"
103
def _get_commands_section(registry, title="Commands", hdg_level1="=",
121
def _dump_text(filename, text):
122
"""Dump text to filename."""
123
f = open(filename, "w")
128
def _get_commands_section(registry, title="Commands", hdg_level1="#",
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())