mailr3800 - /1.3/relax_io.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on November 22, 2007 - 10:49:
Author: bugman
Date: Thu Nov 22 10:49:32 2007
New Revision: 3800

URL: http://svn.gna.org/viewcvs/relax?rev=3800&view=rev
Log:
Modified open_read_file() and open_write_file() to handle file descriptors, 
by returning the arg.


Modified:
    1.3/relax_io.py

Modified: 1.3/relax_io.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/relax_io.py?rev=3800&r1=3799&r2=3800&view=diff
==============================================================================
--- 1.3/relax_io.py (original)
+++ 1.3/relax_io.py Thu Nov 22 10:49:32 2007
@@ -114,6 +114,11 @@
 
 def open_read_file(file_name=None, dir=None, compress_type=0, print_flag=1):
     """Open the file 'file' and return all the data."""
+
+    # A file descriptor object.
+    if type(file_name) == file:
+        # Nothing to do here!
+        return file_name
 
     # File path.
     file_path = get_file_path(file_name, dir)
@@ -139,23 +144,28 @@
         if print_flag:
             print "Opening the file " + `file_path` + " for reading."
         if compress_type == 0:
-            file = open(file_path, 'r')
+            file_obj = open(file_path, 'r')
         elif compress_type == 1:
             if bz2_module:
-                file = BZ2File(file_path, 'r')
+                file_obj = BZ2File(file_path, 'r')
             else:
                 raise RelaxError, "Cannot open the file " + `file_path` + ", 
try uncompressing first.  " + bz2_module_message + "."
         elif compress_type == 2:
-            file = GzipFile(file_path, 'r')
+            file_obj = GzipFile(file_path, 'r')
     except IOError, message:
         raise RelaxError, "Cannot open the file " + `file_path` + ".  " + 
message.args[1] + "."
 
     # Return the opened file.
-    return file
+    return file_obj
 
 
 def open_write_file(file_name=None, dir=None, force=0, compress_type=0, 
print_flag=1, return_path=0):
     """Function for opening a file for writing and creating directories if 
necessary."""
+
+    # A file descriptor object.
+    if type(file_name) == file:
+        # Nothing to do here!
+        return file_name
 
     # The null device.
     if search('devnull', file_name):
@@ -168,13 +178,13 @@
             print "Opening the null device file for writing."
 
         # Open the null device.
-        file = open(devnull, 'w')
+        file_obj = open(devnull, 'w')
 
         # Return the file.
         if return_path:
-            return file, None
+            return file_obj, None
         else:
-            return file
+            return file_obj
 
     # Create the directories.
     mkdir_nofail(dir, print_flag=0)
@@ -206,19 +216,19 @@
         if print_flag:
             print "Opening the file " + `file_path` + " for writing."
         if compress_type == 0:
-            file = open(file_path, 'w')
+            file_obj = open(file_path, 'w')
         elif compress_type == 1:
-            file = BZ2File(file_path, 'w')
+            file_obj = BZ2File(file_path, 'w')
         elif compress_type == 2:
-            file = GzipFile(file_path, 'w')
+            file_obj = GzipFile(file_path, 'w')
     except IOError, message:
         raise RelaxError, "Cannot open the file " + `file_path` + ".  " + 
message.args[1] + "."
 
     # Return the opened file.
     if return_path:
-        return file, file_path
+        return file_obj, file_path
     else:
-        return file
+        return file_obj
 
 
 




Related Messages


Powered by MHonArc, Updated Thu Nov 22 11:20:12 2007