]> git.lyx.org Git - lyx.git/blob - lib/lyx2lyx/lyx2lyx
Move DrawStrategy enum to update_flags.h.
[lyx.git] / lib / lyx2lyx / lyx2lyx
1 #! /usr/bin/python3
2 # Copyright (C) 2002-2011 The LyX Team
3 # Copyright (C) 2002-2007 José Matos <jamatos@lyx.org>
4 # Copyright (C) 2002-2004 Dekel Tsur <dekel@lyx.org>
5 #
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.
10 #
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.
15 #
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
20 " Program used to convert between different versions of the lyx file format."
21 import argparse
22 import sys
23 import LyX
24
25
26 def main():
27     args = {}
28     args["usage"] = "%(prog)s [options] [file]"
29
30     args["description"] = """Convert old lyx file <file> to newer format,
31     files can be compressed with gzip.  If there no file is specified then
32     the standard input is assumed, in this case gziped files are not
33     handled."""
34
35     parser = argparse.ArgumentParser(**args)
36
37     parser.set_defaults(debug=LyX.default_debug__, cjk_encoding = '')
38     parser.add_argument("-d", "--debug", type=int, dest="debug",
39                       help="level=0..2 (O_ quiet, 10_verbose) default: 2")
40     parser.add_argument("-q", "--quiet",
41                       action="store_const", const=0, dest="debug")
42     parser.add_argument("-v", "--verbose",
43                       action="store_const", const=1, dest="debug")
44     parser.add_argument("--noisy",
45                       action="store_const", const=10, dest="debug")
46     parser.add_argument("-c", "--encoding", type=str, dest="cjk_encoding",
47                       help="Files in format 413 and lower are read and"
48                            " written in the format of CJK-LyX."
49                            " If encoding is not given or 'auto' the encoding"
50                            " is determined from the locale.")
51     parser.add_argument("-e", "--err", type=str, dest="error",
52                       help= "File name of the error file else goes to stderr.")
53     parser.add_argument("-o", "--output", type=str, dest="output",
54                       help= "Name of the output file else goes to stdout.")
55     parser.add_argument("-t", "--to", type=str, dest= "end_format",
56                       help= "Destination file format, default <latest>.")
57     parser.add_argument("-V", "--final_version", type=str, dest= "final_version",
58                       help= "Destination version, default <latest>.")
59     parser.add_argument("-l", "--list", action="store_true",
60                       help = "List all available formats and supported versions.")
61     parser.add_argument("-n", "--try-hard", action="store_true",
62                       help = "Try hard (ignore any conversion errors).")
63     parser.add_argument("-s", "--systemlyxdir", type=str, dest= "systemlyxdir",
64                       help= "LyX system directory for conversion from"
65                             " version 489 or older.")
66     parser.add_argument('--version', action='version', version="""lyx2lyx, version %s
67                         Copyright (C) 2011 The LyX Team, José Matos and Dekel Tsur""" % LyX.version__)
68     parser.add_argument("input", nargs='?', type=str, default=None)
69
70     options = parser.parse_args()
71
72     if options.list:
73         sys.stderr.write(LyX.format_info())
74         sys.exit()
75     else:
76         del options.list
77
78     doc = LyX.File(**options.__dict__)
79     doc.convert()
80     doc.write()
81
82     sys.exit(doc.status)
83
84 if __name__ == "__main__":
85     main()