[Lemon-commits] Peter Kovacs: Imporve the titlegen script

Lemon HG hg at lemon.cs.elte.hu
Mon Feb 22 19:46:52 CET 2010


details:   http://lemon.cs.elte.hu/hg/lemon-tutorial/rev/6df2bf124af4
changeset: 42:6df2bf124af4
user:      Peter Kovacs <kpeter [at] inf.elte.hu>
date:      Mon Feb 22 00:40:36 2010 +0100
description:
	Imporve the titlegen script to correctly handle section numbers that
	are greater than ten

diffstat:

 scripts/titlegen.py |  22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)

diffs (46 lines):

diff --git a/scripts/titlegen.py b/scripts/titlegen.py
--- a/scripts/titlegen.py
+++ b/scripts/titlegen.py
@@ -5,6 +5,9 @@
 import copy
 import re
 
+max_sec_number=100
+max_sec_depth=4
+
 def sec_inc(section, lev):
     while len(section)<lev:
         section.append(0)
@@ -19,6 +22,21 @@
     s=s[:-1]
     return s
 
+def compare_sec(id1, id2):
+    id1=id1.split('.')
+    c1=0
+    for s in id1:
+        c1=c1*max_sec_number+int(s)
+    for i in range(len(id1), max_sec_depth+1):
+        c1*=max_sec_number
+    id2=id2.split('.')
+    c2=0
+    for s in id2:
+        c2=c2*max_sec_number+int(s)
+    for i in range(len(id2), max_sec_depth+1):
+        c2*=max_sec_number
+    return c1-c2
+
 section = [];
 toc={}
 ind={}
@@ -69,8 +87,8 @@
                 fo.write('%s| \\ref sec_toc "Home" |%s\n'%\
                              (prev_str,next_str))
             elif gr[3]:
-                secs = [ x for x in toc]
-                secs.sort()
+                secs = [ x for x in toc ]
+                secs.sort(compare_sec)
                 for num in secs:
                     fo.write("%s - \\ref %s\n"%('  '*((len(ind[toc[num]][0]))),
                                                 toc[num]))



More information about the Lemon-commits mailing list