]> git.lyx.org Git - lyx.git/blob - lib/lyx2lyx/lyx2lyx
Whitespace, only whitespace. s/ +$//
[lyx.git] / lib / lyx2lyx / lyx2lyx
1 #! /usr/bin/env python
2 # -*- coding: iso-8859-1 -*-
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     -q, --quiet                 same as --debug=0"""
39
40
41 def parse_options(argv):
42     _options =  ["help", "version", "list", "debug=", "err=", "from=", "to=", "output=", "quiet"]
43     try:
44        opts, args = getopt.getopt(argv[1:], "d:e:f:hlo:qt:v", _options)
45     except getopt.error:
46         usage()
47         sys.exit(2)
48
49     end_format, input, output, error, debug = 0, "", "", "", LyX.default_debug_level
50     for o, a in opts:
51         if o in ("-h", "--help"):
52             usage()
53             sys.exit()
54         if o in ("-v", "--version"):
55             print "lyx2lyx, version %s" %(LyX.version_lyx2lyx)
56             print "Copyright (C) 2002-2004 José Matos and Dekel Tsur"
57             sys.exit()
58         if o in ("-d", "--debug"):
59             debug = int(a)
60         if o in ("-q", "--quiet"):
61             debug = 0
62         if o in ("-l", "--list"):
63             print LyX.formats_list()
64             sys.exit()
65         if o in ("-o", "--output"):
66             output = a
67         if o in ("-t", "--to"):
68             end_format = a
69         if o in ("-e","--err"):
70             error = a
71     if args:
72         input = args[0]
73
74     return end_format, input, output, error, debug
75
76
77 def main(argv):
78     end_format, input, output, error, debug = parse_options(argv)
79     file = LyX.File(end_format, input, output, error, debug)
80
81     file.convert()
82     file.write()
83
84 if __name__ == "__main__":
85     main(sys.argv)