]> git.lyx.org Git - lyx.git/blob - lib/lyx2lyx/lyx2lyx
remerge he.po
[lyx.git] / lib / lyx2lyx / lyx2lyx
1 #! /usr/bin/python3
2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2002-2011 The LyX Team
4 # Copyright (C) 2002-2007 José Matos <jamatos@lyx.org>
5 # Copyright (C) 2002-2004 Dekel Tsur <dekel@lyx.org>
6 #
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
9 # as published by the Free Software Foundation; either version 2
10 # of the License, or (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20
21 " Program used to convert between different versions of the lyx file format."
22 import argparse
23 import sys
24 import LyX
25
26 # Provide support for both python 2 and 3
27 PY2 = sys.version_info[0] == 2
28 if PY2:
29     # argparse returns strings in the commandline encoding, we need to convert.
30     # sys.getdefaultencoding() would not always be correct, see
31     # http://legacy.python.org/dev/peps/pep-0383/
32     def cmd_arg(arg):
33         return arg.decode(sys.getfilesystemencoding())
34 else:
35     cmd_arg = str
36 # End of code to support for both python 2 and 3
37
38 def main():
39     args = {}
40     args["usage"] = "%(prog)s [options] [file]"
41
42     args["description"] = """Convert old lyx file <file> to newer format,
43     files can be compressed with gzip.  If there no file is specified then
44     the standard input is assumed, in this case gziped files are not
45     handled."""
46
47     parser = argparse.ArgumentParser(**args)
48
49     parser.set_defaults(debug=LyX.default_debug__, cjk_encoding = '')
50     parser.add_argument("-d", "--debug", type=int, dest="debug",
51                       help="level=0..2 (O_ quiet, 10_verbose) default: 2")
52     parser.add_argument("-q", "--quiet",
53                       action="store_const", const=0, dest="debug")
54     parser.add_argument("-v", "--verbose",
55                       action="store_const", const=1, dest="debug")
56     parser.add_argument("--noisy",
57                       action="store_const", const=10, dest="debug")
58     parser.add_argument("-c", "--encoding", type=cmd_arg, dest="cjk_encoding",
59                       help="Files in format 413 and lower are read and"
60                            " written in the format of CJK-LyX."
61                            " If encoding is not given or 'auto' the encoding"
62                            " is determined from the locale.")
63     parser.add_argument("-e", "--err", type=cmd_arg, dest="error",
64                       help= "File name of the error file else goes to stderr.")
65     parser.add_argument("-o", "--output", type=cmd_arg, dest="output",
66                       help= "Name of the output file else goes to stdout.")
67     parser.add_argument("-t", "--to", type=cmd_arg, dest= "end_format",
68                       help= "Destination file format, default <latest>.")
69     parser.add_argument("-V", "--final_version", type=cmd_arg, dest= "final_version",
70                       help= "Destination version, default <latest>.")
71     parser.add_argument("-l", "--list", action="store_true",
72                       help = "List all available formats and supported versions.")
73     parser.add_argument("-n", "--try-hard", action="store_true",
74                       help = "Try hard (ignore any conversion errors).")
75     parser.add_argument("-s", "--systemlyxdir", type=cmd_arg, dest= "systemlyxdir",
76                       help= "LyX system directory for conversion from"
77                             " version 489 or older.")
78     parser.add_argument('--version', action='version', version="""lyx2lyx, version %s
79                         Copyright (C) 2011 The LyX Team, José Matos and Dekel Tsur""" % LyX.version__)
80     parser.add_argument("input", nargs='?', type=cmd_arg, default=None)
81
82     options = parser.parse_args()
83
84     if options.list:
85         sys.stderr.write(LyX.format_info())
86         sys.exit()
87     else:
88         del options.list
89
90     doc = LyX.File(**options.__dict__)
91     doc.convert()
92     doc.write()
93
94     sys.exit(doc.status)
95
96 if __name__ == "__main__":
97     main()