mailr3709 - /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 20, 2007 - 18:09:
Author: bugman
Date: Tue Nov 20 18:09:41 2007
New Revision: 3709

URL: http://svn.gna.org/viewcvs/relax?rev=3709&view=rev
Log:
Converted the open_read_file class method to a function.


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=3709&r1=3708&r2=3709&view=diff
==============================================================================
--- 1.3/relax_io.py (original)
+++ 1.3/relax_io.py Tue Nov 20 18:09:41 2007
@@ -78,6 +78,49 @@
     sys.stdin  = log_stdin
     sys.stdout = log_stdout
     sys.stderr = log_stderr
+
+
+def open_read_file(file_name=None, dir=None, compress_type=0, print_flag=1):
+    """Open the file 'file' and return all the data."""
+
+    # File path.
+    file_path = file_path(file_name, dir)
+
+    # Test if the file exists and determine the compression type.
+    if access(file_path, F_OK):
+        compress_type = 0
+        if search('.bz2$', file_path):
+            compress_type = 1
+        elif search('.gz$', file_path):
+            compress_type = 2
+    elif access(file_path + '.bz2', F_OK):
+        file_path = file_path + '.bz2'
+        compress_type = 1
+    elif access(file_path + '.gz', F_OK):
+        file_path = file_path + '.gz'
+        compress_type = 2
+    else:
+        raise RelaxFileError, file_path
+
+    # Open the file for reading.
+    try:
+        if print_flag:
+            print "Opening the file " + `file_path` + " for reading."
+        if compress_type == 0:
+            file = open(file_path, 'r')
+        elif compress_type == 1:
+            if bz2_module:
+                file = 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')
+    except IOError, message:
+        raise RelaxError, "Cannot open the file " + `file_path` + ".  " + 
message.args[1] + "."
+
+    # Return the opened file.
+    return file
+
 
 
 
@@ -223,48 +266,6 @@
         except OSError:
             if print_flag:
                 print "Directory ./" + dir + " already exists.\n"
-
-
-    def open_read_file(self, file_name=None, dir=None, compress_type=0, 
print_flag=1):
-        """Open the file 'file' and return all the data."""
-
-        # File path.
-        file_path = self.file_path(file_name, dir)
-
-        # Test if the file exists and determine the compression type.
-        if access(file_path, F_OK):
-            compress_type = 0
-            if search('.bz2$', file_path):
-                compress_type = 1
-            elif search('.gz$', file_path):
-                compress_type = 2
-        elif access(file_path + '.bz2', F_OK):
-            file_path = file_path + '.bz2'
-            compress_type = 1
-        elif access(file_path + '.gz', F_OK):
-            file_path = file_path + '.gz'
-            compress_type = 2
-        else:
-            raise RelaxFileError, file_path
-
-        # Open the file for reading.
-        try:
-            if print_flag:
-                print "Opening the file " + `file_path` + " for reading."
-            if compress_type == 0:
-                file = open(file_path, 'r')
-            elif compress_type == 1:
-                if bz2_module:
-                    file = 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')
-        except IOError, message:
-            raise RelaxError, "Cannot open the file " + `file_path` + ".  " 
+ message.args[1] + "."
-
-        # Return the opened file.
-        return file
 
 
     def open_write_file(self, file_name=None, dir=None, force=0, 
compress_type=0, print_flag=1, return_path=0):




Related Messages


Powered by MHonArc, Updated Tue Nov 20 18:20:16 2007