COIN-OR::LEMON - Graph Library

source: lemon-tutorial/scripts/titlegen.py @ 41:73fdafd843d9

Last change on this file since 41:73fdafd843d9 was 26:a40eafb6066d, checked in by Peter Kovacs <kpeter@…>, 14 years ago

Distinguish section names from the doc groups

  • Property exe set to *
File size: 2.3 KB
Line 
1#! /usr/bin/env python
2
3import sys
4import os
5import copy
6import re
7
8def sec_inc(section, lev):
9    while len(section)<lev:
10        section.append(0)
11    section[lev-1]+=1
12    section=section[:lev]
13    return section
14
15def format_sec(sec):
16    s=""
17    for i in sec:
18        s+=str(i)+'.'
19    s=s[:-1]
20    return s
21
22section = [];
23toc={}
24ind={}
25
26prev_page=''
27for l in open("toc.txt").readlines():
28    sl = l.split()
29    if len(sl)==2 and len(sl[0])>0:
30        lev=len(sl[0])
31        section=sec_inc(section,lev)
32        t_sec=copy.copy(section)
33        t_link=sl[1];
34        print format_sec(t_sec),t_link
35        ind[t_link]=[t_sec,'','']
36        if lev==1:
37            ind[t_link][1]=prev_page
38            if prev_page:
39                ind[prev_page][2]=t_link
40            prev_page=t_link
41        toc[format_sec(t_sec)]=t_link
42
43for doxfile in os.listdir('.'):
44    if doxfile[-4:]=='.dox':
45        print 'Generate ',doxfile
46        page=''
47        fo=open(os.path.join("gen-dox",doxfile),"w")
48        for l in open(doxfile).readlines():
49            gr = re.match(r"(^[[]PAGE[]].*[[]PAGE[]])?(^[[]SEC[]].*[[]SEC[]])?(^[[]TRAILER[]])?(^[[]TOC[]])?(.*)$", l).groups()
50            if gr[0]:
51                page=gr[0][6:-6]
52                fo.write("\page %s %s%s\n"%(page,
53                                            format_sec(ind[page][0]),gr[4]))
54            elif gr[1]:
55                sec=gr[1][5:-5]
56                fo.write("\section %s %s%s\n"%(sec,
57                                               format_sec(ind[sec][0]),gr[4]))
58            elif gr[2]:
59                prev_page=ind[page][1]
60                if prev_page:
61                    prev_str= ( '<< \\ref '+prev_page+' ')
62                else:
63                    prev_str=''
64                next_page=ind[page][2]
65                if next_page:
66                    next_str= ( ' \\ref '+next_page+' >>')
67                else:
68                    next_str=''
69                fo.write('%s| \\ref sec_toc "Home" |%s\n'%\
70                             (prev_str,next_str))
71            elif gr[3]:
72                secs = [ x for x in toc]
73                secs.sort()
74                for num in secs:
75                    fo.write("%s - \\ref %s\n"%('  '*((len(ind[toc[num]][0]))),
76                                                toc[num]))
77            else:
78                fo.write(gr[4]+'\n')
79        fo.close()
Note: See TracBrowser for help on using the repository browser.