~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 02:44:40 UTC
  • mto: (3119.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 3120.
  • Revision ID: ian.clatworthy@internode.on.net-20071217024440-gb6e5qds0ol0r6sz
Dump help topics into text files in doc/en/user-reference

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 = options.filename
 
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
 
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)
96
113
 
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"
102
119
 
103
120
 
 
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
 
104
128
def _get_commands_section(registry, title="Commands", hdg_level1="#",
105
129
                          hdg_level2="="):
106
130
    """Build the comands reference section of the manual."""