On Tuesday 12 July 2005 22:12, Angus Leeming wrote: > Jose' Matos wrote: > > My proposed patch follows attached as well. > > If '\end_preamble' should always be present can I suggest changing the > warning to something reassuring? > > j = find_token(file.header, '\\end_preamble', i) > if j == -1: > - file.warning("Malformed LyX file: Missing '\\end_preamble'.") > - return > + file.warning("Malformed LyX file: Missing '\\end_preamble' > \nAdding it now and hoping for the best.") > + file.header.append('\\end_preamble')
That is fair. Done. > > This is a superficial fix, I let to those who know better than me to > > decide what to do with the patch. > > If it means that you can now convert a file that would otherwise fail, > then I'd say that you should commit the patch ASAP. OK, you are right. Now lyx2lyx does not break in any file of my repository (there is an exception but I am investigating its origin) either up to 242 or from there to 221 again. Notice again that this does not mean that the convertion is correct it only means that lyx2lyx thinks that it knows what it is doing. :-) The committed patch is attached. I have considered now the case where the paperpackage is empty. -- José Abílio
? l2ly_test.sh Index: lyx_1_4.py =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/lyx2lyx/lyx_1_4.py,v retrieving revision 1.35 diff -u -p -r1.35 lyx_1_4.py --- lyx_1_4.py 7 Jul 2005 10:51:55 -0000 1.35 +++ lyx_1_4.py 12 Jul 2005 21:18:04 -0000 @@ -1047,12 +1047,16 @@ def insert_ert(body, i, status, text): def add_to_preamble(file, text): i = find_token(file.header, '\\begin_preamble', 0) if i == -1: - file.warning("Malformed LyX file: Missing '\\begin_preamble'.") + file.header.extend(['\\begin_preamble'] + text + ['\\end_preamble']) return + j = find_token(file.header, '\\end_preamble', i) if j == -1: file.warning("Malformed LyX file: Missing '\\end_preamble'.") - return + file.warning("Adding it now and hoping for the best.") + file.header.append('\\end_preamble') + j = len(file.header) + if find_token(file.header, text[0], i, j) != -1: return file.header[j:j] = text @@ -1075,8 +1079,8 @@ def convert_frameless_box(file): j = j - 1 # Gather parameters - params = {'position':'0', 'hor_pos':'c', 'has_inner_box':'1', - 'inner_pos':'1', 'use_parbox':'0', 'width':'100col%', + params = {'position':0, 'hor_pos':'c', 'has_inner_box':'1', + 'inner_pos':1, 'use_parbox':'0', 'width':'100col%', 'special':'none', 'height':'1in', 'height_special':'totalheight', 'collapsed':'false'} for key in params.keys(): @@ -1536,8 +1540,11 @@ def revert_paperpackage(file): return packages = {'none':'a4', 'a4':'a4wide', 'a4wide':'widemarginsa4', - 'widemarginsa4':''} - paperpackage = split(file.header[i])[1] + 'widemarginsa4':'', 'default': 'default'} + if len(split(file.header[i])) > 1: + paperpackage = split(file.header[i])[1] + else: + paperpackage = 'default' file.header[i] = replace(file.header[i], paperpackage, packages[paperpackage])