On Tuesday 21 January 2003 18:35, José Matos wrote:
> This patch:
>       * updates the version of lyx2lyx to match the corresponing lyx version;
>       * updates the reference to the copyright date.
>       * adds two new options to list the supported lyx versions, and allow to
> specify it instead of the final file format.
>       * if both the file format and lyx version are given for the resulting file
> it aborts as they are mutually exclusive.
>
> The purpose of this patch is to make lyx2lyx more user friendly and to
> simplify its usage for normal users who wnat to use it for older version of
> lyx.

  Errr.... ignore the last patch, this one is the real. :-)

>       Comments?

-- 
José Abílio
? patch-lyx2lyx
Index: lyx2lyx
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/lyx2lyx/lyx2lyx,v
retrieving revision 1.5
diff -u -p -r1.5 lyx2lyx
--- lyx2lyx	7 Jan 2003 17:03:59 -0000	1.5
+++ lyx2lyx	21 Jan 2003 18:56:19 -0000
@@ -1,5 +1,5 @@
 #! /usr/bin/env python
-# Copyright (C) 2002 José Matos <[EMAIL PROTECTED]>
+# Copyright (C) 2002-2003 José Matos <[EMAIL PROTECTED]>
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -19,7 +19,7 @@ import getopt, sys, string, re
 from error import error, warning
 from parser_tools import set_comment, set_format, check_token
 
-version = "0.0.2"
+version = "1.3.0"
 
 # Allow the dummy object to be able to carry related data
 # like a C struct
@@ -37,7 +37,22 @@ opt.quiet = 0
 
 format = re.compile(r"(\d)[\.,]?(\d\d)")
 fileformat = re.compile(r"\\lyxformat\s*(\S*)")
-lst_ft = ["210", "215", "216", "217", "218", "220", "221"]
+
+lyx_version = {"0.12":"215", "1.0.0":"215", "1.0.1": "215", "1.0.2":"215",
+               "1.0.3":"215", "1.0.4":"215", "1.1.2":"215", "1.1.4":"215",
+               "1.1.5":"216", "1.1.5fix1":"216", "1.1.5fix2":"216",
+               "1.1.6":"217", "1.1.6fix1":"217", "1.1.6fix2":"217",
+               "1.1.6fix3":"218", "1.1.6fix4":"218","1.2.0":"220",
+               "1.2.1":"220", "1.2.2":"220", "1.2.3":"220","1.3.0":"221"}
+lst_ft = []
+lst = lyx_version.values()
+lst.sort()
+#determine unique representation
+value = None
+for item in lst:
+    if item != value:
+        value = item
+        lst_ft.append(value)
 
 def usage():
     print """Usage: lyx2lyx [options] file1
@@ -45,30 +60,34 @@ Convert old lyx file <file1> to newer fo
 Options:
     -h, --help			this information
     -v, --version		output version information and exit
-    -l, --list			list all available formats
+    -l, --list			list all available file formats
+    -m, --list-versions		list all lyx versions supported
     -d, --debug level		level=0..2 (O_ no debug information,2_verbose)
 				default: level=1
-    -f, --from version		initial version (optional)
-    -t, --to version		final version (optional)
+    -f, --from version		initial version
+    -t, --to version		final lyx file format version
+    -n, --final-version version	final lyx version
     -o, --output name		name of the output file or else goes to stdout
     -q, --quiet			same as --debug=0"""
 
 
 def parse_options(argv):
-    _options =  ["help", "version", "list", "from=", "to=", "output=", "quiet"]
+    _options =  ["help", "version", "list", "list-versions", "from=", "to=", "output=", "final-version=", "quiet"]
     try:
-       opts, args = getopt.getopt(argv[1:], "f:hlo:qt:v", _options)
+       opts, args = getopt.getopt(argv[1:], "f:hlmn:o:qt:v", _options)
     except getopt.error:
         usage()
         sys.exit(2)
 
+    output_option = 0
+
     for o, a in opts:
         if o in ("-h", "--help"):
             usage()
             sys.exit()
         if o in ("-v", "--version"):
             print "lyxconvert, version %s" %(version)
-            print "Copyright (C) 2002 LyX Team"
+            print "Copyright (C) 2002-2003 LyX Team"
             sys.exit()
         if o in ("-d", "--debug"):
             opt.debug = int(a)
@@ -77,12 +96,26 @@ def parse_options(argv):
         if o in ("-l", "--list"):
             print lst_ft
             sys.exit()
+        if o in ("-m", "--list-versions"):
+            lyx_versions = lyx_version.keys()
+            lyx_versions.sort()
+            print lyx_versions
+            sys.exit()
         if o in ("-o", "--output"):
             opt.output = open(a, "w")
         if o in ("-f", "--from"):
             opt.start = lyxformat(a)
         if o in ("-t", "--to"):
+            output_option = output_option + 1
             opt.end = lyxformat(a)
+        if o in ("-n","--final-version"):
+            output_option = output_option + 1
+            opt.end = lyxversion[a]
+
+    if output_option == 2:
+        sys.stderr.write("Final output format and final LyX version are mutually exclusive, provide only one of them.\n")
+        usage()
+        sys.exit(2)
 
     if not opt.end:
         opt.end = lst_ft[len(lst_ft)-1]

Reply via email to