]> git.lyx.org Git - features.git/commitdiff
add --try-harder for lyx2lyx
authorJosé Matox <jamatos@lyx.org>
Tue, 5 Jul 2005 11:14:13 +0000 (11:14 +0000)
committerJosé Matox <jamatos@lyx.org>
Tue, 5 Jul 2005 11:14:13 +0000 (11:14 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10131 a592a061-630c-0410-9148-cb99ea01b6c8

lib/lyx2lyx/ChangeLog
lib/lyx2lyx/LyX.py
lib/lyx2lyx/lyx2lyx

index 77250997119d49875d0dea5814668d549980ba5c..dd974627cddec7cea16fc3adb09a44873dd2ef60 100644 (file)
@@ -1,3 +1,12 @@
+2005-07-05  José Matos  <jamatos@lyx.org>
+
+       * LyX.py (LyX_Base):
+       * LyX.py (File):
+       * lyx2lyx (usage):
+       * lyx2lyx (parse_options):      
+       * lyx2lyx (main): Add support for ignoring any errors during the
+       file convertion.
+
 2005-07-05  José Matos  <jamatos@lyx.org>
 
        * lyx_0_12.py (obsolete_latex_title): Obsolote old style.
index e906912e17022c3554576f0833deee9c9ac2cde9..4b5dadcf0d5a96817f81fb495ff41e67e8108565 100644 (file)
@@ -78,7 +78,7 @@ def get_backend(textclass):
 #
 class LyX_Base:
     """This class carries all the information of the LyX file."""
-    def __init__(self, end_format = 0, input = "", output = "", error = "", debug = default_debug_level):
+    def __init__(self, end_format = 0, input = "", output = "", error = "", debug = default_debug_level, try_hard = 0):
         """Arguments:
         end_format: final format that the file should be converted. (integer)
         input: the name of the input source, if empty resort to standard input.
@@ -101,6 +101,7 @@ class LyX_Base:
             self.err = sys.stderr
 
         self.debug = debug
+        self.try_hard = try_hard
 
         if end_format:
             self.end_format = self.lyxformat(end_format)
@@ -282,9 +283,16 @@ class LyX_Base:
 
                 for conv in table:
                     init_t = time.time()
-                    conv(self)
-                    self.warning("%lf: Elapsed time on %s"  % (time.time() - init_t, str(conv)),
-                                 default_debug_level + 1)
+                    try:
+                        conv(self)
+                    except:
+                        self.warning("An error ocurred in %s, %s" % (version, str(conv)),
+                                     default_debug_level)
+                        if not self.try_hard:
+                            raise
+                    else:
+                        self.warning("%lf: Elapsed time on %s"  % (time.time() - init_t, str(conv)),
+                                     default_debug_level + 1)
 
                 self.format = version
                 if self.end_format == self.format:
@@ -414,8 +422,8 @@ class LyX_Base:
 
 class File(LyX_Base):
     " This class reads existing LyX files."
-    def __init__(self, end_format = 0, input = "", output = "", error = "", debug = default_debug_level):
-        LyX_Base.__init__(self, end_format, input, output, error, debug)
+    def __init__(self, end_format = 0, input = "", output = "", error = "", debug = default_debug_level, try_hard = 0):
+        LyX_Base.__init__(self, end_format, input, output, error, debug, try_hard)
         self.read()
 
 
index 7e27f056edbbe9e3a482302120197c2597c069b3..5c63e64ba209df515c5506642a3c696140e8281c 100755 (executable)
@@ -35,18 +35,19 @@ Options:
     -f, --from version         initial version (optional)
     -t, --to version           final version (optional)
     -o, --output name          name of the output file or else goes to stdout
+    -n, --try-hard             try hard (ignore any convertion errors)
     -q, --quiet                        same as --debug=0"""
 
 
 def parse_options(argv):
-    _options =  ["help", "version", "list", "debug=", "err=", "from=", "to=", "output=", "quiet"]
+    _options =  ["help", "version", "list", "debug=", "err=", "from=", "to=", "output=", "try-hard", "quiet"]
     try:
-       opts, args = getopt.getopt(argv[1:], "d:e:f:hlo:qt:v", _options)
+       opts, args = getopt.getopt(argv[1:], "d:e:f:hlno:qt:v", _options)
     except getopt.error:
         usage()
         sys.exit(2)
 
-    end_format, input, output, error, debug = 0, "", "", "", LyX.default_debug_level
+    end_format, input, output, error, debug, try_hard = 0, "", "", "", LyX.default_debug_level, 0
     for o, a in opts:
         if o in ("-h", "--help"):
             usage()
@@ -68,15 +69,17 @@ def parse_options(argv):
             end_format = a
         if o in ("-e","--err"):
             error = a
+        if o in ("-n", "--try-hard"):
+            try_hard = 1
     if args:
         input = args[0]
 
-    return end_format, input, output, error, debug
+    return end_format, input, output, error, debug, try_hard
 
 
 def main(argv):
-    end_format, input, output, error, debug = parse_options(argv)
-    file = LyX.File(end_format, input, output, error, debug)
+    end_format, input, output, error, debug, try_hard = parse_options(argv)
+    file = LyX.File(end_format, input, output, error, debug, try_hard)
 
     file.convert()
     file.write()