scripts/titlegen.py
author Peter Kovacs <kpeter@inf.elte.hu>
Sun, 21 Feb 2010 18:34:28 +0100
changeset 40 e1725bb7e821
parent 17 0b3b26cd1cea
child 42 6df2bf124af4
permissions -rwxr-xr-x
Port two images for SplitNodes from SVN -r3524
alpar@10
     1
#! /usr/bin/env python
alpar@10
     2
alpar@10
     3
import sys
alpar@10
     4
import os
alpar@10
     5
import copy
alpar@10
     6
import re
alpar@10
     7
alpar@10
     8
def sec_inc(section, lev):
alpar@10
     9
    while len(section)<lev:
alpar@10
    10
        section.append(0)
alpar@10
    11
    section[lev-1]+=1
alpar@10
    12
    section=section[:lev]
alpar@10
    13
    return section
alpar@10
    14
alpar@10
    15
def format_sec(sec):
alpar@10
    16
    s=""
alpar@10
    17
    for i in sec:
alpar@10
    18
        s+=str(i)+'.'
alpar@15
    19
    s=s[:-1]
alpar@10
    20
    return s
alpar@10
    21
alpar@10
    22
section = [];
alpar@10
    23
toc={}
alpar@10
    24
ind={}
alpar@10
    25
alpar@10
    26
prev_page=''
alpar@10
    27
for l in open("toc.txt").readlines():
alpar@10
    28
    sl = l.split()
alpar@10
    29
    if len(sl)==2 and len(sl[0])>0: 
alpar@10
    30
        lev=len(sl[0])
alpar@10
    31
        section=sec_inc(section,lev)
alpar@10
    32
        t_sec=copy.copy(section)
alpar@10
    33
        t_link=sl[1];
alpar@10
    34
        print format_sec(t_sec),t_link
alpar@10
    35
        ind[t_link]=[t_sec,'','']
alpar@10
    36
        if lev==1:
alpar@10
    37
            ind[t_link][1]=prev_page
alpar@10
    38
            if prev_page:
alpar@10
    39
                ind[prev_page][2]=t_link
alpar@10
    40
            prev_page=t_link
alpar@10
    41
        toc[format_sec(t_sec)]=t_link
alpar@10
    42
alpar@10
    43
for doxfile in os.listdir('.'):
alpar@10
    44
    if doxfile[-4:]=='.dox':
alpar@10
    45
        print 'Generate ',doxfile
alpar@10
    46
        page=''
alpar@10
    47
        fo=open(os.path.join("gen-dox",doxfile),"w")
alpar@10
    48
        for l in open(doxfile).readlines():
alpar@10
    49
            gr = re.match(r"(^[[]PAGE[]].*[[]PAGE[]])?(^[[]SEC[]].*[[]SEC[]])?(^[[]TRAILER[]])?(^[[]TOC[]])?(.*)$", l).groups()
alpar@10
    50
            if gr[0]:
alpar@10
    51
                page=gr[0][6:-6]
alpar@10
    52
                fo.write("\page %s %s%s\n"%(page,
alpar@10
    53
                                            format_sec(ind[page][0]),gr[4]))
alpar@10
    54
            elif gr[1]:
alpar@10
    55
                sec=gr[1][5:-5]
alpar@10
    56
                fo.write("\section %s %s%s\n"%(sec,
alpar@10
    57
                                               format_sec(ind[sec][0]),gr[4]))
alpar@10
    58
            elif gr[2]:
alpar@10
    59
                prev_page=ind[page][1]
alpar@13
    60
                if prev_page:
alpar@14
    61
                    prev_str= ( '<< \\ref '+prev_page+' ')
alpar@13
    62
                else:
alpar@13
    63
                    prev_str=''
alpar@10
    64
                next_page=ind[page][2]
alpar@13
    65
                if next_page:
alpar@14
    66
                    next_str= ( ' \\ref '+next_page+' >>')
alpar@13
    67
                else:
alpar@13
    68
                    next_str=''
kpeter@26
    69
                fo.write('%s| \\ref sec_toc "Home" |%s\n'%\
alpar@10
    70
                             (prev_str,next_str))
alpar@10
    71
            elif gr[3]:
alpar@10
    72
                secs = [ x for x in toc]
alpar@10
    73
                secs.sort()
alpar@10
    74
                for num in secs:
alpar@15
    75
                    fo.write("%s - \\ref %s\n"%('  '*((len(ind[toc[num]][0]))),
alpar@15
    76
                                                toc[num]))
alpar@10
    77
            else:
alpar@10
    78
                fo.write(gr[4]+'\n')
alpar@10
    79
        fo.close()