[Buildbot-commits] buildbot/buildbot util.py,1.8,1.9 master.py,1.84,1.85
Brian Warner
warner at users.sourceforge.net
Sat Nov 5 22:53:02 UTC 2005
Update of /cvsroot/buildbot/buildbot/buildbot
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4430/buildbot
Modified Files:
util.py master.py
Log Message:
Revision: arch at buildbot.sf.net--2004/buildbot--dev--0--patch-416
Creator: Brian Warner <warner at lothar.com>
use binary mode when opening pickle files, for windows
* buildbot/changes/changes.py (ChangeMaster.saveYourself): use
binary mode when opening pickle files, to make windows work
better. Thanks to Dobes Vandermeer for the catch.
* buildbot/status/builder.py (BuildStatus.saveYourself): same
(BuilderStatus.getBuildByNumber): same
(Status.builderAdded): same
* buildbot/master.py (BuildMaster.loadChanges): same
* buildbot/util.py (Swappable): delete unused leftover code
Index: master.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/master.py,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -d -r1.84 -r1.85
--- master.py 25 Oct 2005 01:57:33 -0000 1.84
+++ master.py 5 Nov 2005 22:52:59 -0000 1.85
@@ -635,7 +635,7 @@
def loadChanges(self):
filename = os.path.join(self.basedir, "changes.pck")
try:
- changes = pickle.load(open(filename, "r"))
+ changes = pickle.load(open(filename, "rb"))
styles.doUpgrade()
except IOError:
log.msg("changes.pck missing, using new one")
Index: util.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/util.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- util.py 24 Apr 2005 21:30:23 -0000 1.8
+++ util.py 5 Nov 2005 22:52:59 -0000 1.9
@@ -41,131 +41,6 @@
return
Deferred._runCallbacks(self)
-from twisted.internet import reactor
-import pickle, os
-
-# objects that can be swapped out to disk when not used
-class Swappable:
- """I am an object with contents that are swapped out to disk when they
- haven't been used for a while. Create me with a timeout and a filename
- where the contents should be pickled. Use .set/.get to manipulate the
- data. You must use .delete to explicitly delete the data.
-
- When this is persisted (or any time __getstate__ is called), the data
- will be swapped to disk first.
-
- t = Swappable(filename='foo')
- t.set(lotsOfData)
- d = t.get()
- t.delete()
- del t
- """
-
- timeout = 5*60 # can be overridden with s.timeout=seconds
-
- def __init__(self):
- self.data = None
- self.timer = None
- self.filed = 0
- self.filename = None
- self.parent = None
- def setFilename(self, parent=None, filename=None):
- log.msg("Swappable.setFilename(%s,%s)" % (parent, filename))
- self.filename = filename
- self.parent = parent
- if self.filename is not None and self.data is not None:
- self.startTimer()
- def computeFilename(self):
- """Most Swappable objects live (in RAM) in a tree of some sort. When
- they move out (to disk), the files they are pickled into are in a
- corresponding tree. If the .parent attribute is set, the object
- will ask it (by calling .getSwappableName()) for a directory to use.
- """
- if self.parent:
- return os.path.join(self.parent.getSwappableName(),
- self.filename)
- return self.filename
-
- def get(self):
- """This will raise an IndexError if the data is unavailable (meaning
- the disk version disappeared).
- """
- log.msg(self, "Swappable.get")
- if self.filed:
- self.load()
- if self.filed:
- # wasn't able to load it
- raise IndexError, "Unable to swap in contents"
- if self.filename is not None:
- self.startTimer()
- return self.data
- def set(self, value):
- if self.filed:
- self.load()
- self.data = value
- if self.filename is not None:
- self.startTimer()
- def delete(self):
- self.stopTimer()
- del self.data
- if self.filed:
- filename = None
- try:
- filename = self.computeFilename()
- self.filed = 0
- os.unlink(filename)
- except:
- log.msg("unable to delete Swappable at '%s'" % filename)
-
- def startTimer(self):
- self.stopTimer()
- self.timer = reactor.callLater(self.timeout, self.fireTimer)
- def stopTimer(self):
- if self.timer:
- self.timer.cancel()
- self.timer = None
- def fireTimer(self):
- self.timer = None
- if not self.filed:
- self.save()
-
- def save(self):
- filename = None
- try:
- filename = self.computeFilename()
- log.msg(self, "Swappable.save(%s)" % filename)
- d = os.path.dirname(filename)
- if d and not os.path.isdir(d):
- os.makedirs(d)
- f = open(filename, "w")
- pickle.dump(self.data, f, 1)
- f.close()
- self.data = None
- self.filed = 1
- except:
- log.msg("unable to save Swappable to '%s'" % filename)
- log.deferr()
- def load(self):
- filename = None
- try:
- filename = self.computeFilename()
- log.msg(self, "Swappable.load(%s)" % filename)
- f = open(filename, "r")
- d = pickle.load(f)
- f.close()
- self.data = d
- self.filed = 0
- os.unlink(filename)
- except:
- log.msg("unable to load Swappable from '%s'" % filename)
- # ignore the error, may happen normally when files are pruned
-
- def __getstate__(self):
- if not self.filed:
- self.stopTimer()
- self.save()
- return self.__dict__
-
def ignoreStaleRefs(failure):
"""d.addErrback(util.ignoreStaleRefs)"""
r = failure.trap(pb.DeadReferenceError, pb.PBConnectionLost)
More information about the Commits
mailing list