#
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.
self.err = sys.stderr
self.debug = debug
+ self.try_hard = try_hard
if end_format:
self.end_format = self.lyxformat(end_format)
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:
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()
-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()
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()