]> git.lyx.org Git - lyx.git/blobdiff - lib/lyx2lyx/LyX.py
Update layouts to format 30.
[lyx.git] / lib / lyx2lyx / LyX.py
index 2a85e446129f6d4a202d34f424f33d8286241a3f..2b9560aac91d2ce6342ca0e40eb9397a7fc15e27 100644 (file)
@@ -32,7 +32,7 @@ try:
     import lyx2lyx_version
     version__ = lyx2lyx_version.version
 except: # we are running from build directory so assume the last version
-    version__ = '1.6.0svn'
+    version__ = '2.0.0svn'
 
 default_debug__ = 2
 
@@ -73,15 +73,27 @@ format_relation = [("0_06",    [200], minor_versions("0.6" , 4)),
                    ("0_12",    [215], minor_versions("0.12", 1) + ["0.11"]),
                    ("1_0",     [215], minor_versions("1.0" , 4)),
                    ("1_1",     [215], minor_versions("1.1" , 4)),
-                   ("1_1_5",   [216], ["1.1.5","1.1.5.1","1.1.5.2","1.1"]),
-                   ("1_1_6_0", [217], ["1.1.6","1.1.6.1","1.1.6.2","1.1"]),
-                   ("1_1_6_3", [218], ["1.1.6.3","1.1.6.4","1.1"]),
+                   ("1_1_5",   [216], ["1.1", "1.1.5","1.1.5.1","1.1.5.2"]),
+                   ("1_1_6_0", [217], ["1.1", "1.1.6","1.1.6.1","1.1.6.2"]),
+                   ("1_1_6_3", [218], ["1.1", "1.1.6.3","1.1.6.4"]),
                    ("1_2",     [220], minor_versions("1.2" , 4)),
                    ("1_3",     [221], minor_versions("1.3" , 7)),
                    ("1_4", range(222,246), minor_versions("1.4" , 5)),
-                   ("1_5", range(246,277), minor_versions("1.5" , 2)),
-                   ("1_6", range(277,333), minor_versions("1.6" , 0))]
+                   ("1_5", range(246,277), minor_versions("1.5" , 7)),
+                   ("1_6", range(277,346), minor_versions("1.6" , 0)),
+                   ("2_0",     [],    minor_versions("2.0", 0))]
 
+####################################################################
+# This is useful just for development versions                     #
+# if the list of supported formats is empty get it from last step  #
+if not format_relation[-1][1]:
+    step, mode = format_relation[-1][0], "convert"
+    convert = getattr(__import__("lyx_" + step), mode)
+    format_relation[-1] = (step,
+                           [conv[0] for conv in convert],
+                           format_relation[-1][2])
+#                                                                  #
+####################################################################
 
 def formats_list():
     " Returns a list with supported file formats."
@@ -93,6 +105,23 @@ def formats_list():
     return formats
 
 
+def format_info():
+    " Returns a list with supported file formats."
+    out = """Major version:
+       minor versions
+       formats
+"""
+    for version in format_relation:
+        major = str(version[2][0])
+        versions = str(version[2][1:])
+        if len(version[1]) == 1:
+            formats = str(version[1][0])
+        else:
+            formats = "%s - %s" % (version[1][-1], version[1][0])
+        out += "%s\n\t%s\n\t%s\n\n" % (major, versions, formats)
+    return out + '\n'
+
+
 def get_end_format():
     " Returns the more recent file format available."
     return format_relation[-1][1][-1]
@@ -102,7 +131,7 @@ def get_backend(textclass):
     " For _textclass_ returns its backend."
     if textclass == "linuxdoc" or textclass == "manpage":
         return "linuxdoc"
-    if textclass[:7] == "docbook":
+    if textclass.startswith("docbook") or textclass.startswith("agu-"):
         return "docbook"
     return "latex"
 
@@ -147,7 +176,7 @@ class LyX_base:
 
     def __init__(self, end_format = 0, input = "", output = "", error = "",
                  debug = default_debug__, try_hard = 0, cjk_encoding = '',
-                 language = "english", encoding = "auto"):
+                 final_version = "", language = "english", encoding = "auto"):
 
         """Arguments:
         end_format: final format that the file should be converted. (integer)
@@ -169,9 +198,37 @@ class LyX_base:
 
         if end_format:
             self.end_format = self.lyxformat(end_format)
+
+            # In case the target version and format are both specified
+            # verify that they are compatible. If not send a warning
+            # and ignore the version.
+            if final_version:
+                message = "Incompatible version %s for specified format %d" % (
+                    final_version, self.end_format)
+                for version in format_relation:
+                    if self.end_format in version[1]:
+                        if final_version not in version[2]:
+                            self.warning(message)
+                            final_version = ""
+        elif final_version:
+            for version in format_relation:
+                if final_version in version[2]:
+                    # set the last format for that version
+                    self.end_format = version[1][-1]
+                    break
+            else:
+                final_version = ""
         else:
             self.end_format = get_end_format()
 
+        if not final_version:
+            for step in format_relation:
+                if self.end_format in step[1]:
+                    final_version = step[2][1]
+        self.final_version = final_version
+        self.warning("Final version: %s" % self.final_version, 10)
+        self.warning("Final format: %d" % self.end_format, 10)
+
         self.backend = "latex"
         self.textclass = "article"
         # This is a hack: We use '' since we don't know the default
@@ -197,7 +254,7 @@ class LyX_base:
         " Emits a warning and exits if not in try_hard mode."
         self.warning(message)
         if not self.try_hard:
-            self.warning("Quiting.")
+            self.warning("Quitting.")
             sys.exit(1)
 
         self.status = 2
@@ -464,16 +521,16 @@ class LyX_base:
 
     def convert(self):
         "Convert from current (self.format) to self.end_format."
-        mode, convertion_chain = self.chain()
-        self.warning("convertion chain: " + str(convertion_chain), 3)
+        mode, conversion_chain = self.chain()
+        self.warning("conversion chain: " + str(conversion_chain), 3)
 
-        for step in convertion_chain:
+        for step in conversion_chain:
             steps = getattr(__import__("lyx_" + step), mode)
 
             self.warning("Convertion step: %s - %s" % (step, mode),
                          default_debug__ + 1)
             if not steps:
-                self.error("The convertion to an older "
+                self.error("The conversion to an older "
                 "format (%s) is not implemented." % self.format)
 
             multi_conv = len(steps) != 1
@@ -506,7 +563,7 @@ class LyX_base:
 
     def chain(self):
         """ This is where all the decisions related with the
-        convertion are taken.  It returns a list of modules needed to
+        conversion are taken.  It returns a list of modules needed to
         convert the LyX file from self.format to self.end_format"""
 
         self.start =  self.format
@@ -545,13 +602,14 @@ class LyX_base:
         steps = []
         if (initial_step, self.start) < (final_step, self.end_format):
             mode = "convert"
-            first_step = 1
+            full_steps = []
             for step in format_relation:
-                if  initial_step <= step[0] <= final_step:
-                    if first_step and len(step[1]) == 1:
-                        first_step = 0
-                        continue
-                    steps.append(step[0])
+                if  initial_step <= step[0] <= final_step and step[2][0] <= self.final_version:
+                    full_steps.append(step)
+            if full_steps[0][1][-1] == self.format:
+                full_steps = full_steps[1:]
+            for step in full_steps:
+                steps.append(step[0])
         else:
             mode = "revert"
             relation_format = format_relation[:]
@@ -635,9 +693,10 @@ class File(LyX_base):
     " This class reads existing LyX files."
 
     def __init__(self, end_format = 0, input = "", output = "", error = "",
-                 debug = default_debug__, try_hard = 0, cjk_encoding = ''):
+                 debug = default_debug__, try_hard = 0, cjk_encoding = '',
+                 final_version = ''):
         LyX_base.__init__(self, end_format, input, output, error,
-                          debug, try_hard, cjk_encoding)
+                          debug, try_hard, cjk_encoding, final_version)
         self.read()