mailr23629 - /trunk/lib/io.py


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

Header


Content

Posted by edward on June 04, 2014 - 10:30:
Author: bugman
Date: Wed Jun  4 10:30:42 2014
New Revision: 23629

URL: http://svn.gna.org/viewcvs/relax?rev=23629&view=rev
Log:
The lib.io.open_write_file() function now automatically determines the 
compression type.

This is used by many user functions which create files.  The end result for a 
user is that if they
supply a '.gz' or '.bz2' file extension, a gzipped or bzipped file will be 
produced.


Modified:
    trunk/lib/io.py

Modified: trunk/lib/io.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/lib/io.py?rev=23629&r1=23628&r2=23629&view=diff
==============================================================================
--- trunk/lib/io.py     (original)
+++ trunk/lib/io.py     Wed Jun  4 10:30:42 2014
@@ -382,24 +382,18 @@
 
     @param file_name:       The name of the file to extract the data from.
     @type file_name:        str
-    @param dir:             The path where the file is located.  If None, 
then the current directory
-                            is assumed.
+    @param dir:             The path where the file is located.  If None, 
then the current directory is assumed.
     @type dir:              str
-    @param force:           Boolean argument which if True causes the file 
to be overwritten if it
-                            already exists.
+    @param force:           Boolean argument which if True causes the file 
to be overwritten if it already exists.
     @type force:            bool
-    @param compress_type:   The compression type.  The integer values 
correspond to the compression
-                            type: 0, no compression; 1, Bzip2 compression; 
2, Gzip compression.
+    @param compress_type:   The compression type.  The integer values 
correspond to the compression type: 0, no compression; 1, Bzip2 compression; 
2, Gzip compression.  If no compression is given but the file name ends in 
'.gz' or '.bz2', then the compression will be automatically set.
     @type compress_type:    int
     @param verbosity:       The verbosity level.
     @type verbosity:        int
-    @param return_path:     If True, the function will return a tuple of the 
file object and the
-                            full file path.
+    @param return_path:     If True, the function will return a tuple of the 
file object and the full file path.
     @type return_path:      bool
-    @return:                The open, writable file object and, if the 
return_path is True, then the
-                            full file path is returned as well.
-    @rtype:                 writable file object (if return_path, then a 
tuple of the writable file
-                            and the full file path)
+    @return:                The open, writable file object and, if the 
return_path is True, then the full file path is returned as well.
+    @rtype:                 writable file object (if return_path, then a 
tuple of the writable file and the full file path)
     """
 
     # No file name?
@@ -436,6 +430,13 @@
 
     # File path.
     file_path = get_file_path(file_name, dir)
+
+    # If no compression is supplied, determine the compression to be used 
from the file extension.
+    if compress_type == 0:
+        if search('.bz2$', file_path):
+            compress_type = 1
+        elif search('.gz$', file_path):
+            compress_type = 2
 
     # Bzip2 compression.
     if compress_type == 1 and not search('.bz2$', file_path):




Related Messages


Powered by MHonArc, Updated Wed Jun 04 10:40:02 2014