]> git.lyx.org Git - lyx.git/commitdiff
lyx2lyx supports gziped files, version header correct
authorJosé Matox <jamatos@lyx.org>
Mon, 28 Jul 2003 21:14:33 +0000 (21:14 +0000)
committerJosé Matox <jamatos@lyx.org>
Mon, 28 Jul 2003 21:14:33 +0000 (21:14 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7426 a592a061-630c-0410-9148-cb99ea01b6c8

lib/ChangeLog
lib/lyx2lyx/lyx2lyx
lib/lyx2lyx/parser_tools.py

index 42f3bcbd13af630cb24457e9e31e73a5129df796..e1092cf5b6d2d4588bf0d45f54b933a5174bbce8 100644 (file)
@@ -1,3 +1,8 @@
+2003-07-28  José Matos  <jamatos@lyx.org>
+
+       * lyx2lyx (parse_options): support gziped files.
+       * parser_tools.py (set_format): output correct version.
+
 2003-07-28  José Matos  <jamatos@fep.up.pt>
 
        * lyx2lyx/lyx_convert224.py (layout2begin_layout):
index 6ee6cb5977272db30da6aaf28e65d8593ecdecd6..c7629b9c22533a006e51b3d884ac4b62255597cf 100755 (executable)
@@ -18,8 +18,9 @@
 import getopt, sys, string, re
 from error import error, warning
 from parser_tools import set_comment, set_format, check_token
+import gzip
 
-version = "0.0.2"
+version = "1.4.0cvs"
 
 # Allow the dummy object to be able to carry related data
 # like a C struct
@@ -40,8 +41,10 @@ fileformat = re.compile(r"\\lyxformat\s*(\S*)")
 lst_ft = ["210", "215", "216", "217", "218", "220", "221", "223", "224", "225"]
 
 def usage():
-    print """Usage: lyx2lyx [options] file1
-Convert old lyx file <file1> to newer format.
+    print """Usage: lyx2lyx [options] [file]
+Convert old lyx file <file> to newer format, files can be compressed with gzip.
+If there no file is specified then the standard input is assumed, in this case
+gziped files are not handled.
 Options:
     -h, --help                 this information
     -v, --version              output version information and exit
@@ -68,7 +71,7 @@ def parse_options(argv):
             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)
@@ -96,7 +99,13 @@ def parse_options(argv):
         sys.exit(1)
 
     if args:
-        opt.input = open(args[0])
+        file = args[0]
+        try:
+            gzip.open(file).readline()
+            opt.output = gzip.GzipFile("","wb",6,opt.output)
+            opt.input = gzip.open(file)
+        except:
+            opt.input = open(file)
 
 def lyxformat(fmt):
     result = format.match(fmt)
@@ -182,7 +191,7 @@ def main(argv):
     for fmt in lst_ft[start:end]:
        __import__("lyxconvert_" + fmt).convert(header,body)
 
-    set_comment(header, opt.end)
+    set_comment(header, version)
     set_format(header, opt.end)
     write_file(opt.output, header, body)
     
index 312fa4fa357af8ebc8f44274b12607f877c140a5..465e174d3a863dce9645e04948f926a7105bd2a5 100644 (file)
@@ -173,22 +173,13 @@ def find_nonempty_line(lines, start, end = 0):
            return i
     return -1
 
-def set_comment(lines, number):
-    x = int(number)
-    if x < 216:
-       # It is not worth the trouble to handle this case
-       return
-    elif x < 220:
-       version = "1.1"
-    else:
-       version = str((x-220)/10.0+1.2)
-
+def set_comment(lines, version):
     lines[0] = "#LyX %s created this file. For more info see http://www.lyx.org/" % version
     if lines[1][0] == '#':
        del lines[1]
 
 def set_format(lines, number):
     if int(number) <= 217:
-       number = float(number)/100
+        number = float(number)/100
     i = find_token(lines, "\\lyxformat", 0)
     lines[i] = "\\lyxformat %s" % number