[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[minion-cvs] Add functionality to upgrade server homedirs.
Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv23333/lib/mixminion
Modified Files:
Common.py
Log Message:
Add functionality to upgrade server homedirs.
If all my code were somehow bug-free, 0.0.4 would now be finished.
Time to start testing and debugging!
Index: Common.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Common.py,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -d -r1.78 -r1.79
--- Common.py 26 May 2003 20:04:16 -0000 1.78
+++ Common.py 28 May 2003 04:53:34 -0000 1.79
@@ -7,15 +7,14 @@
__all__ = [ 'IntervalSet', 'Lockfile', 'LOG', 'LogStream', 'MixError',
'MixFatalError', 'MixProtocolError', 'UIError', 'UsageError',
- 'armorText',
- 'ceilDiv', 'checkPrivateDir', 'checkPrivateFile',
+ 'armorText', 'ceilDiv', 'checkPrivateDir', 'checkPrivateFile',
'createPrivateDir', 'encodeBase64', 'floorDiv', 'formatBase64',
'formatDate', 'formatFnameTime', 'formatTime',
'installSIGCHLDHandler', 'isSMTPMailbox', 'openUnique',
- 'previousMidnight', 'readPickled', 'readPossiblyGzippedFile',
- 'secureDelete', 'stringContains', 'succeedingMidnight',
- 'unarmorText',
- 'waitForChildren', 'writePickled' ]
+ 'previousMidnight', 'readFile', 'readPickled',
+ 'readPossiblyGzippedFile', 'secureDelete', 'stringContains',
+ 'succeedingMidnight', 'unarmorText', 'waitForChildren',
+ 'writeFile', 'writePickled' ]
import binascii
import bisect
@@ -394,6 +393,28 @@
def __del__(self):
if self.f:
LOG.error("Atomic file not closed/discarded: %s",self.tmpname)
+
+def readFile(fn, binary=0):
+ """DOCDOC"""
+ f = open(fn, ['r', 'rb'][binary])
+ try:
+ return f.read()
+ finally:
+ f.close()
+
+def writeFile(fn, contents, mode=0600, binary=0):
+ tmpname = fn+".tmp"
+ f, tmpname = openUnique(tmpname, ['w','wb'][binary], mode)
+ try:
+ try:
+ f.write(contents)
+ finally:
+ f.close()
+ except:
+ if os.path.exists(tmpname): os.unlink(tmpname)
+ raise
+
+ os.rename(tmpname, fn)
def readPickled(fn):
"""Given the name of a file containing a pickled object, return the pickled