]> git.lyx.org Git - lyx.git/blob - lib/lyx2lyx/lyx2lyx
new \lyxline difinition, fixes also bug 1988:
[lyx.git] / lib / lyx2lyx / lyx2lyx
1 #! /usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2002-2004 José Matos <jamatos@lyx.org>
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 import getopt
20 import sys
21 import LyX
22
23 def usage():
24     print """Usage: lyx2lyx [options] [file]
25 Convert old lyx file <file> to newer format, files can be compressed with gzip.
26 If there no file is specified then the standard input is assumed, in this case
27 gziped files are not handled.
28 Options:
29     -h, --help                  this information
30     -v, --version               output version information and exit
31     -l, --list                  list all available formats
32     -d, --debug level           level=0..2 (O_ no debug information, 2_verbose)
33                                 default: level=1
34     -e, --err error_file        name of the error file or else goes to stderr
35     -f, --from version          initial version (optional)
36     -t, --to version            final version (optional)
37     -o, --output name           name of the output file or else goes to stdout
38     -n, --try-hard              try hard (ignore any convertion errors)
39     -q, --quiet                 same as --debug=0"""
40
41
42 def parse_options(argv):
43     _options =  ["help", "version", "list", "debug=", "err=", "from=", "to=", "output=", "try-hard", "quiet"]
44     try:
45        opts, args = getopt.getopt(argv[1:], "d:e:f:hlno:qt:v", _options)
46     except getopt.error:
47         usage()
48         sys.exit(2)
49
50     end_format, input, output, error, debug, try_hard = 0, "", "", "", LyX.default_debug_level, 0
51     for o, a in opts:
52         if o in ("-h", "--help"):
53             usage()
54             sys.exit()
55         if o in ("-v", "--version"):
56             print "lyx2lyx, version %s" %(LyX.version_lyx2lyx)
57             print "Copyright (C) 2002-2004 José Matos and Dekel Tsur"
58             sys.exit()
59         if o in ("-d", "--debug"):
60             debug = int(a)
61         if o in ("-q", "--quiet"):
62             debug = 0
63         if o in ("-l", "--list"):
64             print LyX.formats_list()
65             sys.exit()
66         if o in ("-o", "--output"):
67             output = a
68         if o in ("-t", "--to"):
69             end_format = a
70         if o in ("-e","--err"):
71             error = a
72         if o in ("-n", "--try-hard"):
73             try_hard = 1
74     if args:
75         input = args[0]
76
77     return end_format, input, output, error, debug, try_hard
78
79
80 def main(argv):
81     end_format, input, output, error, debug, try_hard = parse_options(argv)
82     file = LyX.File(end_format, input, output, error, debug, try_hard)
83
84     file.convert()
85     file.write()
86
87     return file.status
88
89
90 if __name__ == "__main__":
91     sys.exit(main(sys.argv))