From d65491ab5ad62d62a2b887e06dcaf0e124083495 Mon Sep 17 00:00:00 2001 From: jamatos Date: Wed, 5 Jan 2005 18:52:59 +0000 Subject: [PATCH] Unify the call to converters into LyX.py. (lyx2lyx) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9442 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/lyx2lyx/ChangeLog | 18 ++++++++ lib/lyx2lyx/LyX.py | 28 +++++++++++-- lib/lyx2lyx/lyx2lyx | 2 +- lib/lyx2lyx/lyx_0_12.py | 28 ++++--------- lib/lyx2lyx/lyx_1_0_0.py | 13 +----- lib/lyx2lyx/lyx_1_0_1.py | 13 +----- lib/lyx2lyx/lyx_1_1_4.py | 13 +----- lib/lyx2lyx/lyx_1_1_5.py | 17 ++------ lib/lyx2lyx/lyx_1_1_6.py | 13 +----- lib/lyx2lyx/lyx_1_1_6fix3.py | 13 +----- lib/lyx2lyx/lyx_1_2.py | 19 +++------ lib/lyx2lyx/lyx_1_3.py | 13 +----- lib/lyx2lyx/lyx_1_4.py | 97 ++++++++++++++++++-------------------------- 13 files changed, 110 insertions(+), 177 deletions(-) diff --git a/lib/lyx2lyx/ChangeLog b/lib/lyx2lyx/ChangeLog index 23173f9e76..b7f1028538 100644 --- a/lib/lyx2lyx/ChangeLog +++ b/lib/lyx2lyx/ChangeLog @@ -1,5 +1,23 @@ 2005-01-04 José Matos + * lyx_0_12.py: + * lyx_1_0_0.py: + * lyx_1_0_1.py: + * lyx_1_1_4.py: + * lyx_1_1_5.py: + * lyx_1_1_6.py: + * lyx_1_1_6fix3.py: + * lyx_1_2.py: + * lyx_1_3.py: + * lyx_1_4.py: convert and revert change from functions to lists. + + * LyX.py: + * lyx2lyx: version -> version_lyx2lyx + + * LyX.py (convert): put all the convertion logic here. + +2005-01-04 José Matos + * LyX.py (set_format): fix typo. * lyx_0_12.py: diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py index b08fce2abd..df8baa3d8a 100644 --- a/lib/lyx2lyx/LyX.py +++ b/lib/lyx2lyx/LyX.py @@ -23,7 +23,7 @@ import sys import re import string -version = "1.4.0cvs" +version_lyx2lyx = "1.4.0cvs" default_debug_level = 2 # Regular expressions used @@ -224,7 +224,7 @@ class LyX_Base: def set_version(self): " Set the header with the version used." - self.header[0] = "#LyX %s created this file. For more info see http://www.lyx.org/" % version + self.header[0] = "#LyX %s created this file. For more info see http://www.lyx.org/" % version_lyx2lyx if self.header[1][0] == '#': del self.header[1] @@ -265,8 +265,28 @@ class LyX_Base: self.warning("convertion chain: " + str(convertion_chain), 3) for step in convertion_chain: - convert_step = getattr(__import__("lyx_" + step), mode) - convert_step(self) + steps = getattr(__import__("lyx_" + step), mode) + + if not steps: + self.error("The convertion to an older format (%s) is not implemented." % self.format) + + if len(steps) == 1: + version, table = steps[0] + for conv in table: + conv(self) + self.format = version + continue + + for version, table in steps: + if self.format >= version and mode == "convert": + continue + if self.format <= version and mode == "revert": + continue + for conv in table: + conv(self) + self.format = version + if self.end_format == self.format: + return def chain(self): diff --git a/lib/lyx2lyx/lyx2lyx b/lib/lyx2lyx/lyx2lyx index 162c348e05..f355240b55 100755 --- a/lib/lyx2lyx/lyx2lyx +++ b/lib/lyx2lyx/lyx2lyx @@ -51,7 +51,7 @@ def parse_options(argv): usage() sys.exit() if o in ("-v", "--version"): - print "lyx2lyx, version %s" %(LyX.version) + print "lyx2lyx, version %s" %(LyX.version_lyx2lyx) print "Copyright (C) 2002-2004 José Matos and Dekel Tsur" sys.exit() if o in ("-d", "--debug"): diff --git a/lib/lyx2lyx/lyx_0_12.py b/lib/lyx2lyx/lyx_0_12.py index 31d38b66e4..7eedd02f1a 100644 --- a/lib/lyx2lyx/lyx_0_12.py +++ b/lib/lyx2lyx/lyx_0_12.py @@ -137,11 +137,6 @@ def update_space_units(file): lines[i] = string.replace(lines[i], old, new) -def update_inset_accent(file): - lines = file.body - pass - - def remove_cursor(file): lines = file.body i = 0 @@ -278,22 +273,13 @@ def update_latexaccents(file): i = i + 1 -def convert(file): - table = [header_update, add_end_document, remove_cursor, - final_dot, update_inset_label, update_latexdel, - update_space_units, update_inset_accent, - space_before_layout, formula_inset_space_eat, - update_tabular, update_vfill, remove_empty_insets, - remove_formula_latex, update_latexaccents] - - for conv in table: - conv(file) - - file.format = 215 - - -def revert(file): - file.error("The convertion to an older format (%s) is not implemented." % file.format) +convert = [[215, [header_update, add_end_document, remove_cursor, + final_dot, update_inset_label, update_latexdel, + update_space_units, space_before_layout, + formula_inset_space_eat, update_tabular, + update_vfill, remove_empty_insets, + remove_formula_latex, update_latexaccents]]] +revert = [] if __name__ == "__main__": diff --git a/lib/lyx2lyx/lyx_1_0_0.py b/lib/lyx2lyx/lyx_1_0_0.py index c191b79b6e..199fb3022a 100644 --- a/lib/lyx2lyx/lyx_1_0_0.py +++ b/lib/lyx2lyx/lyx_1_0_0.py @@ -16,17 +16,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -def convert(file): - table = [] - - for conv in table: - conv(file) - - file.format = 215 - - -def revert(file): - file.error("The convertion to an older format (%s) is not implemented." % file .format) +convert = [[215, []]] +revert = [] if __name__ == "__main__": diff --git a/lib/lyx2lyx/lyx_1_0_1.py b/lib/lyx2lyx/lyx_1_0_1.py index 43c08274ef..199fb3022a 100644 --- a/lib/lyx2lyx/lyx_1_0_1.py +++ b/lib/lyx2lyx/lyx_1_0_1.py @@ -16,17 +16,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -def convert(file): - table = [] - - for conv in table: - conv(file) - - file.format = 215 - - -def revert(file): - file.error("The convertion to an older format (%s) is not implemented." % file.format) +convert = [[215, []]] +revert = [] if __name__ == "__main__": diff --git a/lib/lyx2lyx/lyx_1_1_4.py b/lib/lyx2lyx/lyx_1_1_4.py index 43c08274ef..199fb3022a 100644 --- a/lib/lyx2lyx/lyx_1_1_4.py +++ b/lib/lyx2lyx/lyx_1_1_4.py @@ -16,17 +16,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -def convert(file): - table = [] - - for conv in table: - conv(file) - - file.format = 215 - - -def revert(file): - file.error("The convertion to an older format (%s) is not implemented." % file.format) +convert = [[215, []]] +revert = [] if __name__ == "__main__": diff --git a/lib/lyx2lyx/lyx_1_1_5.py b/lib/lyx2lyx/lyx_1_1_5.py index 6e8fa21a2d..4f533a9c6d 100644 --- a/lib/lyx2lyx/lyx_1_1_5.py +++ b/lib/lyx2lyx/lyx_1_1_5.py @@ -155,19 +155,10 @@ def remove_space_in_units(file): i = i + 1 -def convert(file): - table = [first_layout, remove_vcid, remove_cursor, update_toc, - replace_protected_separator, merge_formula_inset, - update_tabular, remove_space_in_units] - - for conv in table: - conv(file) - - file.format = 216 - - -def revert(file): - file.error("The convertion to an older format (%s) is not implemented." % file.format) +convert = [[216, [first_layout, remove_vcid, remove_cursor, update_toc, + replace_protected_separator, merge_formula_inset, + update_tabular, remove_space_in_units]]] +revert = [] if __name__ == "__main__": pass diff --git a/lib/lyx2lyx/lyx_1_1_6.py b/lib/lyx2lyx/lyx_1_1_6.py index 9e849629b1..67b114a0b6 100644 --- a/lib/lyx2lyx/lyx_1_1_6.py +++ b/lib/lyx2lyx/lyx_1_1_6.py @@ -276,17 +276,8 @@ def update_language(file): return -def convert(file): - table = [update_tabular, update_language] - - for conv in table: - conv(file) - - file.format = 217 - - -def revert(file): - file.error("The convertion to an older format (%s) is not implemented." % file.format) +convert = [[217, [update_tabular, update_language]]] +revert = [] if __name__ == "__main__": diff --git a/lib/lyx2lyx/lyx_1_1_6fix3.py b/lib/lyx2lyx/lyx_1_1_6fix3.py index 837f320394..74b19d27e2 100644 --- a/lib/lyx2lyx/lyx_1_1_6fix3.py +++ b/lib/lyx2lyx/lyx_1_1_6fix3.py @@ -114,17 +114,8 @@ def table_update(lines): return lines[:2] + col_info + lines[2:] -def convert(file): - table = [update_tabular] - - for conv in table: - conv(file) - - file.format = 218 - - -def revert(file): - file.error("The convertion to an older format (%s) is not implemented." % file.format) +convert = [[218, [update_tabular]]] +revert = [] if __name__ == "__main__": diff --git a/lib/lyx2lyx/lyx_1_2.py b/lib/lyx2lyx/lyx_1_2.py index 2e3063d2e0..d42540f1bf 100644 --- a/lib/lyx2lyx/lyx_1_2.py +++ b/lib/lyx2lyx/lyx_1_2.py @@ -730,20 +730,11 @@ def change_preamble(file): "\use_numerical_citations 0"] -def convert(file): - table = [change_preamble, change_listof, fix_oldfloatinset, - update_tabular, update_longtables, remove_pextra, - remove_oldfloat, remove_figinset, remove_oldertinset, - remove_oldert, combine_ert, change_infoinset] - - for conv in table: - conv(file) - - file.format = 220 - - -def revert(file): - file.error("The convertion to an older format (%s) is not implemented." % file.format) +convert = [[220, [change_preamble, change_listof, fix_oldfloatinset, + update_tabular, update_longtables, remove_pextra, + remove_oldfloat, remove_figinset, remove_oldertinset, + remove_oldert, combine_ert, change_infoinset]]] +revert = [] if __name__ == "__main__": diff --git a/lib/lyx2lyx/lyx_1_3.py b/lib/lyx2lyx/lyx_1_3.py index 978b883d7e..7ced9af7fd 100644 --- a/lib/lyx2lyx/lyx_1_3.py +++ b/lib/lyx2lyx/lyx_1_3.py @@ -92,17 +92,8 @@ def change_tabular(file): i = i+1 -def convert(file): - table = [change_insetgraphics, change_tabular] - - for conv in table: - conv(file) - - file.format = 221 - - -def revert(file): - file.error("The convertion to an older format (%s) is not implemented." % file.format) +convert = [[221, [change_insetgraphics, change_tabular]]] +revert = [] if __name__ == "__main__": diff --git a/lib/lyx2lyx/lyx_1_4.py b/lib/lyx2lyx/lyx_1_4.py index 242fa6821f..0722503a42 100644 --- a/lib/lyx2lyx/lyx_1_4.py +++ b/lib/lyx2lyx/lyx_1_4.py @@ -1510,66 +1510,47 @@ def use_x_binary(file): ## # Convertion hub # -def convert(file): - table = [[223, [insert_tracking_changes, add_end_header, remove_color_default, - convert_spaces, convert_bibtex, remove_insetparent]], - [224, [convert_external, convert_comment]], - [225, [add_end_layout, layout2begin_layout, convert_end_document, - convert_table_valignment_middle, convert_breaks]], - [226, [convert_note]], - [227, [convert_box]], - [228, [convert_collapsable, convert_ert]], - [229, [convert_minipage]], - [230, [convert_jurabib]], - [231, [convert_float]], - [232, [convert_bibtopic]], - [233, [convert_graphics, convert_names]], - [234, [convert_cite_engine]], - [235, [convert_paperpackage]], - [236, [convert_bullets, add_begin_header, add_begin_body, - normalize_papersize, strip_end_space]], - [237, [use_x_boolean]], - [238, [update_latexaccents]]] - - for version, conv_steps in table: - if file.format >= version: - continue - for convert in conv_steps: - convert(file) - file.format = version - if file.end_format == file.format: - return +convert = [[223, [insert_tracking_changes, add_end_header, remove_color_default, + convert_spaces, convert_bibtex, remove_insetparent]], + [224, [convert_external, convert_comment]], + [225, [add_end_layout, layout2begin_layout, convert_end_document, + convert_table_valignment_middle, convert_breaks]], + [226, [convert_note]], + [227, [convert_box]], + [228, [convert_collapsable, convert_ert]], + [229, [convert_minipage]], + [230, [convert_jurabib]], + [231, [convert_float]], + [232, [convert_bibtopic]], + [233, [convert_graphics, convert_names]], + [234, [convert_cite_engine]], + [235, [convert_paperpackage]], + [236, [convert_bullets, add_begin_header, add_begin_body, + normalize_papersize, strip_end_space]], + [237, [use_x_boolean]], + [238, [update_latexaccents]]] + +revert = [[237, []], + [236, [use_x_binary]], + [235, [denormalize_papersize, remove_begin_body,remove_begin_header, + revert_bullets]], + [234, [revert_paperpackage]], + [233, [revert_cite_engine]], + [232, [revert_names]], + [231, [revert_bibtopic]], + [230, [revert_float]], + [229, [revert_jurabib]], + [228, []], + [227, [revert_collapsable, revert_ert]], + [226, [revert_box, revert_external_2]], + [225, [revert_note]], + [224, [rm_end_layout, begin_layout2layout, revert_end_document, + revert_valignment_middle, convert_vspace, convert_frameless_box]], + [223, [revert_external_2, revert_comment]], + [221, [rm_end_header, revert_spaces, revert_bibtex, + rm_tracking_changes, rm_body_changes]]] -def revert(file): - table = [[237, []], - [236, [use_x_binary]], - [235, [denormalize_papersize, remove_begin_body,remove_begin_header, - revert_bullets]], - [234, [revert_paperpackage]], - [233, [revert_cite_engine]], - [232, [revert_names]], - [231, [revert_bibtopic]], - [230, [revert_float]], - [229, [revert_jurabib]], - [228, []], - [227, [revert_collapsable, revert_ert]], - [226, [revert_box, revert_external_2]], - [225, [revert_note]], - [224, [rm_end_layout, begin_layout2layout, revert_end_document, - revert_valignment_middle, convert_vspace, convert_frameless_box]], - [223, [revert_external_2, revert_comment]], - [221, [rm_end_header, revert_spaces, revert_bibtex, - rm_tracking_changes, rm_body_changes]]] - - for version, conv_steps in table: - if file.format <= version: - continue - for convert in conv_steps: - convert(file) - file.format = version - if file.end_format == file.format: - return if __name__ == "__main__": pass -- 2.11.4.GIT