scripts/titlegen.py
changeset 53 0f695eac7e07
parent 26 a40eafb6066d
child 59 5d9170b19285
equal deleted inserted replaced
1:782aae3fd3f6 2:3a49dd30094e
     2 
     2 
     3 import sys
     3 import sys
     4 import os
     4 import os
     5 import copy
     5 import copy
     6 import re
     6 import re
       
     7 
       
     8 max_sec_number=100
       
     9 max_sec_depth=4
     7 
    10 
     8 def sec_inc(section, lev):
    11 def sec_inc(section, lev):
     9     while len(section)<lev:
    12     while len(section)<lev:
    10         section.append(0)
    13         section.append(0)
    11     section[lev-1]+=1
    14     section[lev-1]+=1
    16     s=""
    19     s=""
    17     for i in sec:
    20     for i in sec:
    18         s+=str(i)+'.'
    21         s+=str(i)+'.'
    19     s=s[:-1]
    22     s=s[:-1]
    20     return s
    23     return s
       
    24 
       
    25 def compare_sec(id1, id2):
       
    26     id1=id1.split('.')
       
    27     c1=0
       
    28     for s in id1:
       
    29         c1=c1*max_sec_number+int(s)
       
    30     for i in range(len(id1), max_sec_depth+1):
       
    31         c1*=max_sec_number
       
    32     id2=id2.split('.')
       
    33     c2=0
       
    34     for s in id2:
       
    35         c2=c2*max_sec_number+int(s)
       
    36     for i in range(len(id2), max_sec_depth+1):
       
    37         c2*=max_sec_number
       
    38     return c1-c2
    21 
    39 
    22 section = [];
    40 section = [];
    23 toc={}
    41 toc={}
    24 ind={}
    42 ind={}
    25 
    43 
    67                 else:
    85                 else:
    68                     next_str=''
    86                     next_str=''
    69                 fo.write('%s| \\ref sec_toc "Home" |%s\n'%\
    87                 fo.write('%s| \\ref sec_toc "Home" |%s\n'%\
    70                              (prev_str,next_str))
    88                              (prev_str,next_str))
    71             elif gr[3]:
    89             elif gr[3]:
    72                 secs = [ x for x in toc]
    90                 secs = [ x for x in toc ]
    73                 secs.sort()
    91                 secs.sort(compare_sec)
    74                 for num in secs:
    92                 for num in secs:
    75                     fo.write("%s - \\ref %s\n"%('  '*((len(ind[toc[num]][0]))),
    93                     fo.write("%s - \\ref %s\n"%('  '*((len(ind[toc[num]][0]))),
    76                                                 toc[num]))
    94                                                 toc[num]))
    77             else:
    95             else:
    78                 fo.write(gr[4]+'\n')
    96                 fo.write(gr[4]+'\n')