2006-08-02 09:54:41 +00:00
|
|
|
#! /usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright (C) 2002-2004 José Matos <jamatos@lyx.org>
|
2002-08-01 15:26:32 +00:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
2004-04-14 08:45:46 +00:00
|
|
|
import getopt
|
|
|
|
import sys
|
2004-08-15 16:29:04 +00:00
|
|
|
import LyX
|
2004-05-11 16:13:33 +00:00
|
|
|
|
2002-08-01 15:26:32 +00:00
|
|
|
def usage():
|
2003-07-28 21:14:33 +00:00
|
|
|
print """Usage: lyx2lyx [options] [file]
|
|
|
|
Convert old lyx file <file> to newer format, files can be compressed with gzip.
|
|
|
|
If there no file is specified then the standard input is assumed, in this case
|
|
|
|
gziped files are not handled.
|
2002-08-01 15:26:32 +00:00
|
|
|
Options:
|
|
|
|
-h, --help this information
|
|
|
|
-v, --version output version information and exit
|
|
|
|
-l, --list list all available formats
|
2004-04-14 08:45:46 +00:00
|
|
|
-d, --debug level level=0..2 (O_ no debug information, 2_verbose)
|
2002-08-01 15:26:32 +00:00
|
|
|
default: level=1
|
2003-12-05 20:09:24 +00:00
|
|
|
-e, --err error_file name of the error file or else goes to stderr
|
2005-05-19 08:43:52 +00:00
|
|
|
-f, --from version initial version (optional)
|
2002-08-01 15:26:32 +00:00
|
|
|
-t, --to version final version (optional)
|
|
|
|
-o, --output name name of the output file or else goes to stdout
|
2005-07-05 11:14:13 +00:00
|
|
|
-n, --try-hard try hard (ignore any convertion errors)
|
2002-08-01 15:26:32 +00:00
|
|
|
-q, --quiet same as --debug=0"""
|
|
|
|
|
|
|
|
|
2004-08-15 16:29:04 +00:00
|
|
|
def parse_options(argv):
|
2005-07-05 11:14:13 +00:00
|
|
|
_options = ["help", "version", "list", "debug=", "err=", "from=", "to=", "output=", "try-hard", "quiet"]
|
2002-08-01 15:26:32 +00:00
|
|
|
try:
|
2005-07-05 11:14:13 +00:00
|
|
|
opts, args = getopt.getopt(argv[1:], "d:e:f:hlno:qt:v", _options)
|
2002-08-01 15:26:32 +00:00
|
|
|
except getopt.error:
|
|
|
|
usage()
|
|
|
|
sys.exit(2)
|
|
|
|
|
2005-07-05 11:14:13 +00:00
|
|
|
end_format, input, output, error, debug, try_hard = 0, "", "", "", LyX.default_debug_level, 0
|
2002-08-01 15:26:32 +00:00
|
|
|
for o, a in opts:
|
|
|
|
if o in ("-h", "--help"):
|
|
|
|
usage()
|
|
|
|
sys.exit()
|
|
|
|
if o in ("-v", "--version"):
|
2005-01-05 18:52:59 +00:00
|
|
|
print "lyx2lyx, version %s" %(LyX.version_lyx2lyx)
|
2006-08-02 09:54:41 +00:00
|
|
|
print "Copyright (C) 2002-2004 José Matos and Dekel Tsur"
|
2002-08-01 15:26:32 +00:00
|
|
|
sys.exit()
|
|
|
|
if o in ("-d", "--debug"):
|
2004-08-15 16:29:04 +00:00
|
|
|
debug = int(a)
|
2002-08-01 15:26:32 +00:00
|
|
|
if o in ("-q", "--quiet"):
|
2004-08-15 16:29:04 +00:00
|
|
|
debug = 0
|
2002-08-01 15:26:32 +00:00
|
|
|
if o in ("-l", "--list"):
|
2004-10-09 21:32:56 +00:00
|
|
|
print LyX.formats_list()
|
2002-08-01 15:26:32 +00:00
|
|
|
sys.exit()
|
|
|
|
if o in ("-o", "--output"):
|
2004-08-15 16:29:04 +00:00
|
|
|
output = a
|
2002-08-01 15:26:32 +00:00
|
|
|
if o in ("-t", "--to"):
|
2004-08-15 16:29:04 +00:00
|
|
|
end_format = a
|
2003-12-05 20:09:24 +00:00
|
|
|
if o in ("-e","--err"):
|
2004-08-15 16:29:04 +00:00
|
|
|
error = a
|
2005-07-05 11:14:13 +00:00
|
|
|
if o in ("-n", "--try-hard"):
|
|
|
|
try_hard = 1
|
2002-08-01 15:26:32 +00:00
|
|
|
if args:
|
2004-08-15 16:29:04 +00:00
|
|
|
input = args[0]
|
2004-05-11 16:13:33 +00:00
|
|
|
|
2005-07-05 11:14:13 +00:00
|
|
|
return end_format, input, output, error, debug, try_hard
|
2004-04-14 08:45:46 +00:00
|
|
|
|
2002-08-01 15:26:32 +00:00
|
|
|
|
2004-10-10 19:25:48 +00:00
|
|
|
def main(argv):
|
2005-07-05 11:14:13 +00:00
|
|
|
end_format, input, output, error, debug, try_hard = parse_options(argv)
|
|
|
|
file = LyX.File(end_format, input, output, error, debug, try_hard)
|
2004-04-14 08:45:46 +00:00
|
|
|
|
2004-10-16 22:56:10 +00:00
|
|
|
file.convert()
|
2004-08-15 16:29:04 +00:00
|
|
|
file.write()
|
2004-10-10 19:25:48 +00:00
|
|
|
|
2005-07-05 15:28:44 +00:00
|
|
|
return file.status
|
|
|
|
|
|
|
|
|
2004-10-10 19:25:48 +00:00
|
|
|
if __name__ == "__main__":
|
2005-07-05 15:28:44 +00:00
|
|
|
sys.exit(main(sys.argv))
|