mailr8683 - /1.3/relax_errors.py


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

Header


Content

Posted by edward on January 27, 2009 - 18:48:
Author: bugman
Date: Tue Jan 27 18:48:32 2009
New Revision: 8683

URL: http://svn.gna.org/viewcvs/relax?rev=8683&view=rev
Log:
Improvements to the relax_errors module.

The module function save_state() can now function if this module is used by 
something other than
relax.  The saved state is also BZip compressed if the bz2 module exists.


Modified:
    1.3/relax_errors.py

Modified: 1.3/relax_errors.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/relax_errors.py?rev=8683&r1=8682&r2=8683&view=diff
==============================================================================
--- 1.3/relax_errors.py (original)
+++ 1.3/relax_errors.py Tue Jan 27 18:48:32 2009
@@ -25,6 +25,11 @@
 
 
 # Python module imports.
+try:
+    from bz2 import BZ2File
+    bz2 = True
+except ImportError:
+    bz2 = False
 from cPickle import dump
 from re import match
 import time
@@ -38,14 +43,22 @@
     """Save the program state, for debugging purposes."""
 
     # relax data store singleton import.  Must be done here!
-    from data import Relax_data_store; ds = Relax_data_store()
+    try:
+        from data import Relax_data_store; ds = Relax_data_store()
+
+    # Ok, this is not relax so don't do anything!
+    except ImportError:
+        return
 
     # Append the date and time to the save file.
     now = time.localtime()
     file_name = "relax_state_%i%02i%02i_%02i%02i%02i" % (now[0], now[2], 
now[1], now[3], now[4], now[5])
 
     # Open the file for writing.
-    file = open(file_name, 'w')
+    if bz2:
+        file = BZ2File(file_name+'.bz2', 'w')
+    else:
+        file = open(file_name, 'w')
 
     # Pickle the data class and write it to file
     dump(ds, file, 1)




Related Messages


Powered by MHonArc, Updated Tue Jan 27 19:00:05 2009