[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[minion-cvs] Support for gzipped pickles
Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv20705/lib/mixminion
Modified Files:
Common.py
Log Message:
Support for gzipped pickles
Index: Common.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Common.py,v
retrieving revision 1.141
retrieving revision 1.142
diff -u -d -r1.141 -r1.142
--- Common.py 27 Jul 2004 03:05:47 -0000 1.141
+++ Common.py 27 Jul 2004 21:51:18 -0000 1.142
@@ -597,24 +597,28 @@
replaceFile(tmpname, fn)
-def readPickled(fn):
+def readPickled(fn, gzipped=0):
"""Given the name of a file containing a pickled object, return the pickled
object."""
f = open(fn, 'rb')
+ if gzipped:
+ f = gzip.GzipFile(fileobj=f, mode='rb')
try:
return cPickle.load(f)
finally:
f.close()
-def writePickled(fn, obj, mode=0600):
+def writePickled(fn, obj, mode=0600, gzipped=0):
"""Given a filename and an object to be pickled, pickles the object into
a temporary file, then replaces the file with the temporary file.
"""
tmpname = fn + ".tmp"
f, tmpname = openUnique(tmpname, 'wb', mode)
+ if gzipped:
+ f = gzip.GzipFile(fileobj=f, filename=fn, mode='wb')
try:
try:
- cPickle.dump(obj, f, 1)
+ cPickle.dump(obj, f, -1)
finally:
f.close()
except: