]> git.lyx.org Git - features.git/commitdiff
fix lyx2lyx bug dealing with compressed files.
authorJosé Matox <jamatos@lyx.org>
Thu, 1 Dec 2005 19:00:07 +0000 (19:00 +0000)
committerJosé Matox <jamatos@lyx.org>
Thu, 1 Dec 2005 19:00:07 +0000 (19:00 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10640 a592a061-630c-0410-9148-cb99ea01b6c8

lib/lyx2lyx/ChangeLog
lib/lyx2lyx/LyX.py

index ad247b5ab7230585744a2a52f7597ea2fe85240f..9329edd684148dc691502009b8a63af81a4508e2 100644 (file)
@@ -1,3 +1,7 @@
+2005-12-01  José Matos  <jamatos@lyx.org>
+
+       * LyX.py (choose_io): replace open and make the choice more transparent.
+
 2005-11-24  José Matos  <jamatos@lyx.org>
 
        * lyx_1_0_0.py (obsolete_latex_title): "LaTeX Title" -> "Title"
index 7a30eb76846f64c169474e5b40a2eb4af748158e..729425bb3988c2ed01fac55e3f7ddb53ced641f5 100644 (file)
@@ -94,14 +94,7 @@ class LyX_Base:
         error: the name of the error file, if empty use the standard error.
         debug: debug level, O means no debug, as its value increases be more verbose.
         """
-        if input and input != '-':
-            self.input = self.open(input)
-        else:
-            self.input = sys.stdin
-        if output:
-            self.output = open(output, "w")
-        else:
-            self.output = sys.stdout
+        self.choose_io(input, output)
 
         if error:
             self.err = open(error, "w")
@@ -212,16 +205,25 @@ class LyX_Base:
             self.output.write(line+"\n")
 
 
-    def open(self, file):
-        """Transparently deals with compressed files."""
+    def choose_io(self, input, output):
+        """Choose input and output streams, dealing transparently with
+        compressed files."""
 
-        self.dir = os.path.dirname(os.path.abspath(file))
-        try:
-            gzip.open(file).readline()
-            self.output = gzip.GzipFile("","wb",6,self.output)
-            return gzip.open(file)
-        except:
-            return open(file)
+        if output:
+            self.output = open(output, "wb")
+        else:
+            self.output = sys.stdout
+
+        if input and input != '-':
+            self.dir = os.path.dirname(os.path.abspath(input))
+            try:
+                gzip.open(input).readline()
+                self.input = gzip.open(input)
+                self.output = gzip.GzipFile(mode="wb", fileobj=self.output) 
+            except:
+                self.input = open(input)
+        else:
+            self.input = sys.stdin
 
 
     def lyxformat(self, format):