]> git.lyx.org Git - lyx.git/blobdiff - lib/lyx2lyx/lyxconvert_217.py
Test for the presence of rpmbuild.
[lyx.git] / lib / lyx2lyx / lyxconvert_217.py
index 3b27d54c93415a612a0547641e30e3f770365ef0..b55bd7d0ae3d5cb45b6cae05e7b39f3e3b0c8d22 100644 (file)
 import re, string, sys
 from parser_tools import *
 
-bool_table =  {"0": "false", "1":"true" }
+def bool_table(item):
+    if item == "0":
+        return "false"
+    # should emit a warning if item != "1"
+    return "true"
+
 align_table = {"0": "top", "2": "left", "4": "right", "8": "center"}
 use_table = {"0": "none", "1": "parbox"}
 
-#table_meta_re = re.compile(r'<LyXTabular version="1" rows="(\d*)" columns="(\d*)">')
+table_meta_re = re.compile(r'<LyXTabular version="?1"? rows="?(\d*)"? columns="?(\d*)"?>')
 def update_tabular(lines):
     i=0
     while 1:
@@ -33,7 +38,10 @@ def update_tabular(lines):
         i = i +1
 
         # scan table header meta-info
-        lines[i] = string.replace(lines[i], 'LyXTabular version="1"', 'lyxtabular version="2"')
+        res = table_meta_re.match( lines[i] )
+        if res:
+            val = res.groups()
+            lines[i] = '<lyxtabular version="2" rows="%s" columns="%s">' % val
 
         j = find_token(lines, '</LyXTabular>', i) + 1
         if j == 0:
@@ -44,17 +52,17 @@ def update_tabular(lines):
        lines[i:j] = new_table
         i = i + len(new_table)
 
-col_re = re.compile(r'<column alignment="(\d)" valignment="(\d)" leftline="(\d)" rightline="(\d)" width="(.*)" special="(.*)">')
-cell_re = re.compile(r'<cell multicolumn="(\d)" alignment="(\d)" valignment="(\d)" topline="(\d)" bottomline="(\d)" leftline="(\d)" rightline="(\d)" rotate="(\d)" usebox="(\d)" width="(.*)" special="(.*)">')
-features_re = re.compile(r'<features rotate="(\d)" islongtable="(\d)" endhead="(\d)" endfirsthead="(\d)" endfoot="(\d)" endlastfoot="(\d)">')
-row_re = re.compile(r'<row topline="(\d)" bottomline="(\d)" newpage="(\d)">')
+col_re = re.compile(r'<column alignment="?(\d)"? valignment="?(\d)"? leftline="?(\d)"? rightline="?(\d)"? width="(.*)" special="(.*)">')
+cell_re = re.compile(r'<cell multicolumn="?(\d)"? alignment="?(\d)"? valignment="?(\d)"? topline="?(\d)"? bottomline="?(\d)"? leftline="?(\d)"? rightline="?(\d)"? rotate="?(\d)"? usebox="?(\d)"? width="(.*)" special="(.*)">')
+features_re = re.compile(r'<features rotate="?(\d)"? islongtable="?(\d)"? endhead="?(-?\d)"? endfirsthead="?(-?\d)"? endfoot="?(-?\d)"? endlastfoot="?(-?\d)"?>')
+row_re = re.compile(r'<row topline="?(\d)"? bottomline="?(\d)"? newpage="?(\d)"?>')
 
 def table_update(lines):
     lines[1] = string.replace(lines[1], '<Features', '<features')
     res = features_re.match( lines[1] )
     if res:
         val = res.groups()
-        lines[1] = '<features rotate="%s" islongtable="%s" endhead="%s" endfirsthead="%s" endfoot="%s" endlastfoot="%s">' % (bool_table[val[0]], bool_table[val[1]], val[2], val[3], val[4], val[5])
+        lines[1] = '<features rotate="%s" islongtable="%s" endhead="%s" endfirsthead="%s" endfoot="%s" endlastfoot="%s">' % (bool_table(val[0]), bool_table(val[1]), val[2], val[3], val[4], val[5])
         
     if lines[2]=="":
         del lines[2]
@@ -81,12 +89,12 @@ def table_update(lines):
         res = cell_re.match(lines[i])
         if res:
             val = res.groups()
-            lines[i] = '<cell multicolumn="%s" alignment="%s" valignment="%s" topline="%s" bottomline="%s" leftline="%s" rightline="%s" rotate="%s" usebox="%s" width="%s" special="%s">' % ( val[0], align_table[val[1]], align_table[val[2]], bool_table[val[3]], bool_table[val[4]], bool_table[val[5]], bool_table[val[6]], bool_table[val[7]], use_table[val[8]], val[9], val[10])
+            lines[i] = '<cell multicolumn="%s" alignment="%s" valignment="%s" topline="%s" bottomline="%s" leftline="%s" rightline="%s" rotate="%s" usebox="%s" width="%s" special="%s">' % ( val[0], align_table[val[1]], align_table[val[2]], bool_table(val[3]), bool_table(val[4]), bool_table(val[5]), bool_table(val[6]), bool_table(val[7]), use_table[val[8]], val[9], val[10])
 
         res = row_re.match(lines[i])
         if res:
             val = res.groups()
-            lines[i] = '<row topline="%s" bottomline="%s" newpage="%s">' % (bool_table[val[0]], bool_table[val[1]], bool_table[val[2]])
+            lines[i] = '<row topline="%s" bottomline="%s" newpage="%s">' % (bool_table(val[0]), bool_table(val[1]), bool_table(val[2]))
 
         i = i + 1
 
@@ -96,7 +104,7 @@ def table_update(lines):
         if res:
             val = res.groups()
             col_info[i] = '<column alignment="%s" valignment="%s" leftline="%s" rightline="%s" width="%s" special="%s">' \
-                          % ( align_table[val[0]], align_table[val[1]], bool_table[val[2]], bool_table[val[3]], val[4],val[5])
+                          % ( align_table[val[0]], align_table[val[1]], bool_table(val[2]), bool_table(val[3]), val[4],val[5])
 
     return lines[:2] + col_info + lines[2:]