Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/mpl/doc/src/refmanual/refmanual.py @ 29

Last change on this file since 29 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 3.6 KB
Line 
1# Copyright (c) Aleksey Gurtovoy 2001-2007
2#
3# Distributed under the Boost Software License, Version 1.0.
4# (See accompanying file LICENSE_1_0.txt or copy at
5# http://www.boost.org/LICENSE_1_0.txt)
6
7import time
8import fnmatch
9import os.path
10import os
11import re
12import string
13
14underlines = ['+', '/']
15special_cases = [ 'inserter', '_1,_2,..._n' ]
16
17
18def __section_header(section):
19    parts = section.split('/')
20    underline = underlines[len(parts) - 1] * len(parts[-1])
21    if len(parts) > 0:
22        hidden_target = '.. _`label-%s`:' % '-'.join( parts )
23        return '\n%s\n%s\n%s\n\n' % (parts[-1], underline, hidden_target )
24    else:
25        return '\n%s\n%s\n\n' % (parts[-1], underline )
26
27
28def __section_intro(section):
29    parts = section.split('/')
30    return '%s.rst' % '-'.join( [x.split(' ')[0] for x in parts] )
31
32
33def __include_page( output, page, name = None ):
34    output.write( '.. include:: %s\n' % page )     
35    # output.write( '.. raw:: LaTeX\n\n' )
36    # output.write( '   \\newpage\n\n')
37   
38    if name and name not in special_cases: ref = name
39    else:    ref = '/'.join( page.split('.')[0].split('-') )
40    if ref.upper() == ref or ref.lower() == ref:
41        output.write( 
42              ( '.. |%(ref)s| replace:: |``%(ref)s``|__\n'
43                + '.. |``%(ref)s``| replace:: :refentry:`%(ref)s`\n'
44                + '__ `%(ref)s`_\n' ) 
45                    % { 'ref': ref }
46            )
47    else:
48        if ref.find( '/' ) == -1:
49            ref = ' '.join( filter( lambda x: len(x) > 0, re.split( '([A-Z][a-z]+)', ref ) ) )
50            output.write( '.. |%(ref)s| replace:: `%(ref)s`_\n' % { 'ref': ref } )
51
52    modtime = time.gmtime( os.stat( page ).st_mtime )   
53    output.write( '.. modtime: %s\n' % time.strftime( '%B %d, %Y %H:%M:%S +0000', modtime ) )
54    output.write( '\n' )
55
56
57def __write_index( filename, index ):
58    index_file = open( filename, 'w' )
59    index.sort()
60    for x in index:
61        index_file.write( '* |%s|\n' % x )
62   
63    index_file.close()
64
65
66def main( filename, dir ):
67    sources = filter(
68          lambda x: fnmatch.fnmatch(x,"*.rst") and x != filename
69        , os.listdir(dir)
70        )
71
72    toc = [t.strip() for t in open('%s.toc' % filename).readlines()]
73    topics = {}
74    for t in toc: topics[t] = []
75
76    concept_index = []
77    index = []
78
79    output = open('%s.gen' % filename, 'w')
80    output.writelines( open( '%s.rst' % filename, 'r' ).readlines() )
81    re_topic = re.compile(r'^..\s+(.+?)//(.+?)(\s*\|\s*(\d+))?\s*$')
82    for src in sources:
83        placement_spec = open(src, 'r').readline()
84       
85        topic = 'Unclassified'
86        name = None
87        order = -1
88       
89        match = re_topic.match(placement_spec)
90        if match:
91            topic = match.group(1)
92            name = match.group(2)
93            if match.group(3):
94                order = int(match.group(4))
95       
96        if not topics.has_key(topic):
97            topics[topic] = []
98       
99        topics[topic].append((src, order, name))
100       
101        if name:
102            if topic.find( '/Concepts' ) == -1:
103                index.append( name )
104            else:
105                concept_index.append( name )
106       
107
108    for t in toc:
109        content = topics[t]
110        content.sort( lambda x,y: x[1] - y[1] )
111       
112        output.write( __section_header(t) )
113
114        intro = __section_intro(t)
115        if os.path.exists(intro):
116            __include_page( output, intro )
117       
118        for src in content:
119            __include_page( output, src[0], src[2] )
120
121    output.close()
122
123    __write_index( 'concepts.gen', concept_index )
124    __write_index( 'index.gen', index )
125   
126   
127
128main( 'refmanual', os.getcwd() )
Note: See TracBrowser for help on using the repository browser.