From 9b4136de38a2ca45b28bdc78c1ab65abfaa688bf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Matox?= Date: Tue, 5 Jul 2005 11:14:13 +0000 Subject: [PATCH] add --try-harder for lyx2lyx git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10131 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/lyx2lyx/ChangeLog | 9 +++++++++ lib/lyx2lyx/LyX.py | 20 ++++++++++++++------ lib/lyx2lyx/lyx2lyx | 15 +++++++++------ 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/lib/lyx2lyx/ChangeLog b/lib/lyx2lyx/ChangeLog index 7725099711..dd974627cd 100644 --- a/lib/lyx2lyx/ChangeLog +++ b/lib/lyx2lyx/ChangeLog @@ -1,3 +1,12 @@ +2005-07-05 José Matos + + * 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 * lyx_0_12.py (obsolete_latex_title): Obsolote old style. diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py index e906912e17..4b5dadcf0d 100644 --- a/lib/lyx2lyx/LyX.py +++ b/lib/lyx2lyx/LyX.py @@ -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() diff --git a/lib/lyx2lyx/lyx2lyx b/lib/lyx2lyx/lyx2lyx index 7e27f056ed..5c63e64ba2 100755 --- a/lib/lyx2lyx/lyx2lyx +++ b/lib/lyx2lyx/lyx2lyx @@ -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() -- 2.39.2