From 0b24926473229a375a6a576502e20d810300cad9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Matox?= Date: Fri, 3 Oct 2003 17:11:22 +0000 Subject: [PATCH] support backward saving for 1.3.x format. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7857 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/ChangeLog | 7 ++++ lib/lyx2lyx/lyx2lyx | 27 +++++-------- lib/lyx2lyx/lyxrevert_223.py | 54 ++++++++++++++++++++++++++ lib/lyx2lyx/lyxrevert_224.py | 59 ++++++++++++++++++++++++++++ lib/lyx2lyx/lyxrevert_225.py | 75 ++++++++++++++++++++++++++++++++++++ 5 files changed, 205 insertions(+), 17 deletions(-) create mode 100644 lib/lyx2lyx/lyxrevert_223.py create mode 100644 lib/lyx2lyx/lyxrevert_224.py create mode 100644 lib/lyx2lyx/lyxrevert_225.py diff --git a/lib/ChangeLog b/lib/ChangeLog index 21fdcd114c..c1f1c80839 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,10 @@ +2003-10-03 José Matos + + * lyx2lxy: + * lyxrevert_223.py: + * lyxrevert_224.py: + * lyxrevert_225.py: support backward saving for 1.3.x format. + 2003-09-27 Jürgen Spitzmüller * layouts/memoir.layout: More sensible order; new env "legend". diff --git a/lib/lyx2lyx/lyx2lyx b/lib/lyx2lyx/lyx2lyx index 0dd6248323..c8cf03f82e 100755 --- a/lib/lyx2lyx/lyx2lyx +++ b/lib/lyx2lyx/lyx2lyx @@ -39,7 +39,7 @@ opt.quiet = 0 format = re.compile(r"(\d)[\.,]?(\d\d)") fileformat = re.compile(r"\\lyxformat\s*(\S*)") -lst_ft = ["210", "215", "216", "217", "218", "220", "221", "223", "224", "225"] +lst_ft = [210, 215, 216, 217, 218, 220, 221, 223, 224, 225] def usage(): print """Usage: lyx2lyx [options] [file] @@ -91,14 +91,6 @@ def parse_options(argv): if not opt.end: opt.end = lst_ft[len(lst_ft)-1] - if opt.start and opt.start == opt.end: - sys.stderr.write(error.same_format) - sys.exit() - - if opt.start > opt.end: - sys.stderr.write(error.newer_format) - sys.exit(1) - if args: file = args[0] try: @@ -111,19 +103,14 @@ def parse_options(argv): def lyxformat(fmt): result = format.match(fmt) if result: - fmt = result.group(1)+result.group(2) + fmt = int(result.group(1) + result.group(2)) else: - sys.stderr.write(fmt + ": " + error.invalid_format) + sys.stderr.write(str(fmt) + ": " + error.invalid_format) sys.exit(2) if fmt in lst_ft: return fmt - x = int(fmt) - if x < int(lst_ft[-1]) and x > int(lst_ft[-2]): - sys.stderr.write("lyx2lyx: A development version file.\n") - return lst_ft[-2] - sys.stderr.write(fmt + ": " + error.format_not_supported) sys.exit(1) @@ -186,11 +173,17 @@ def main(argv): opt.start = fmt # Convertion chain + if opt.start < opt.end: + mode = "lyxconvert_" + else: + lst_ft.reverse() + mode = "lyxrevert_" + start = lst_ft.index(opt.start) end = lst_ft.index(opt.end) for fmt in lst_ft[start:end]: - __import__("lyxconvert_" + fmt).convert(header,body) + __import__(mode + str(fmt)).convert(header,body) set_comment(header, version) set_format(header, opt.end) diff --git a/lib/lyx2lyx/lyxrevert_223.py b/lib/lyx2lyx/lyxrevert_223.py new file mode 100644 index 0000000000..086c8cd48d --- /dev/null +++ b/lib/lyx2lyx/lyxrevert_223.py @@ -0,0 +1,54 @@ +# This file is part of lyx2lyx +# Copyright (C) 2003 José Matos +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +import string +from parser_tools import find_token + +def rm_end_header(lines): + i = find_token(lines, "\\end_header", 0) + if i == -1: + return + del lines[i] + +def convert_spaces(lines): + for i in range(len(lines)): + lines[i] = string.replace(lines[i],"\\InsetSpace ~", "\\SpecialChar ~") + +def convert_bibtex(lines): + for i in range(len(lines)): + lines[i] = string.replace(lines[i], "\\begin_inset LatexCommand \\bibtex", + "\\begin_inset LatexCommand \\BibTeX") + +def rm_tracking_changes(lines): + i = find_token(lines, "\\tracking_changes", 0) + if i == -1: + return + del lines[i] + +#FIXME +def rm_body_changes(lines): + pass + +def convert(header, body): + rm_end_header(header) + convert_spaces(body) + convert_bibtex(body) + rm_tracking_changes(header) + rm_body_changes(body) + +if __name__ == "__main__": + pass diff --git a/lib/lyx2lyx/lyxrevert_224.py b/lib/lyx2lyx/lyxrevert_224.py new file mode 100644 index 0000000000..1c15914565 --- /dev/null +++ b/lib/lyx2lyx/lyxrevert_224.py @@ -0,0 +1,59 @@ +# This file is part of lyx2lyx +# Copyright (C) 2003 José Matos +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +from string import split, join +from parser_tools import find_token, find_tokens + +def convert_external(lines): + external_header = "\\begin_inset External" + i = 0 + while 1: + i = find_token(lines, external_header, i) + if i == -1: + break + + template = split(lines[i+1]) + template.reverse() + del lines[i+1] + + filename = split(lines[i+1]) + filename.reverse() + del lines[i+1] + + params = split(lines[i+1]) + params.reverse() + if lines[i+1]: del lines[i+1] + + lines[i] = lines[i] + " " + template[0]+ ', "' + filename[0] + '", " '+ join(params[1:]) + '"' + i = i + 1 + +def convert_comment(lines): + i = 0 + while 1: + i = find_tokens(lines, ["\\begin_inset Comment", "\\begin_inset Greyedout"], i) + + if i == -1: + return + lines[i] = "\\begin_inset Note" + i = i + 1 + +def convert(header, body): + convert_external(body) + convert_comment(body) + +if __name__ == "__main__": + pass diff --git a/lib/lyx2lyx/lyxrevert_225.py b/lib/lyx2lyx/lyxrevert_225.py new file mode 100644 index 0000000000..2a953dbc8d --- /dev/null +++ b/lib/lyx2lyx/lyxrevert_225.py @@ -0,0 +1,75 @@ +# This file is part of lyx2lyx +# Copyright (C) 2003 José Matos +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +import re +from parser_tools import find_token, find_end_of_inset +from string import replace + +def rm_end_layout(lines): + i = 0 + while 1: + i = find_token(lines, '\\end_layout', i) + + if i == -1: + return + + del lines[i] + +def begin_layout2layout(lines): + i = 0 + while 1: + i = find_token(lines, '\\begin_layout', i) + if i == -1: + return + + lines[i] = replace(lines[i], '\\begin_layout', '\\layout') + i = i + 1 + +def table_valignment_middle(lines, start, end): + for i in range(start, end): + if re.search('^<(column|cell) .*valignment="middle".*>$', lines[i]): + lines[i] = replace(lines[i], 'valignment="middle"', 'valignment="center"') + +def valignment_middle(lines): + i = 0 + while 1: + i = find_token(lines, '\\begin_inset Tabular', i) + if i == -1: + return + j = find_end_of_inset(lines, i + 1) + if j == -1: + #this should not happen + valignment_middle(lines, i + 1, len(lines)) + return + valignment_middle(lines, i + 1, j) + i = j + 1 + +def end_document(lines): + i = find_token(lines, "\\end_document", 0) + if i == -1: + lines.append("\\the_end") + return + lines[i] = "\\the_end" + +def convert(header, body): + rm_end_layout(body) + begin_layout2layout(body) + end_document(body) + valignment_middle(body) + +if __name__ == "__main__": + pass -- 2.39.2