tufte layout files:
[lyx.git] / lib / lyx2lyx / lyx2lyx
blobc1c9f188d66b26cfb26ccf72a28c1e4031fe3c02
1 #! /usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2002-2007 José Matos <jamatos@lyx.org>
4 # Copyright (C) 2002-2004 Dekel Tsur <dekel@lyx.org>
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 " Program used to convert between different versions of the lyx file format."
21 import optparse
22 import sys
23 import LyX
25 def main():
26 args = {}
27 args["usage"] = "usage: %prog [options] [file]"
29 args["version"] = """lyx2lyx, version %s
30 Copyright (C) 2007 José Matos and Dekel Tsur""" % LyX.version__
32 args["description"] = """Convert old lyx file <file> to newer format,
33 files can be compressed with gzip. If there no file is specified then
34 the standard input is assumed, in this case gziped files are not
35 handled."""
37 parser = optparse.OptionParser(**args)
39 parser.set_defaults(debug=LyX.default_debug__, cjk_encoding = '')
40 parser.add_option("-d", "--debug", type="int",
41 help="level=0..2 (O_ quiet, 10_verbose) default: 2")
42 parser.add_option("-q", "--quiet",
43 action="store_const", const=0, dest="debug")
44 parser.add_option("-v", "--verbose",
45 action="store_const", const=1, dest="debug")
46 parser.add_option("--noisy",
47 action="store_const", const=10, dest="debug")
48 parser.add_option("-c", "--encoding", dest="cjk_encoding",
49 help="files in format 248 and lower are read and"
50 " written in the format of CJK-LyX."
51 "If encoding is not given or 'auto' the encoding"
52 "is determined from the locale.")
53 parser.add_option("-e", "--err", dest="error",
54 help= "file name of the error file else goes to stderr")
55 parser.add_option("-o", "--output",
56 help= "name of the output file else goes to stdout")
57 parser.add_option("-t", "--to", dest= "end_format",
58 help= "destination file format, default (latest)")
59 parser.add_option("-V", "--final_version", dest= "final_version",
60 help= "destination version, default (latest)")
61 parser.add_option("-l", "--list", action="store_true",
62 help = "list all available formats and supported versions")
63 parser.add_option("-n", "--try-hard", action="store_true",
64 help = "try hard (ignore any convertion errors)")
66 (options, args) = parser.parse_args()
67 if args:
68 options.input = args[0]
69 else:
70 options.input = None
72 if options.list:
73 sys.stderr.write(LyX.format_info())
74 sys.exit()
75 else:
76 del options.list
78 doc = LyX.File(**options.__dict__)
79 doc.convert()
80 doc.write()
82 sys.exit(doc.status)
84 if __name__ == "__main__":
85 main()