Several small utilities are available at the top-level buildbot.util
package. As always, see the API documentation for more information.
natualSortwinslave1, winslave2, ..
formatIntervalComparableMixin class Widget(FactoryProduct, ComparableMixin):
compare_attrs = [ 'radius', 'thickness' ]
# ...
Any attributes not in compare_attrs will not be considered when
comparing objects. This is particularly useful in implementing buildbot's
reconfig logic, where a simple comparison between the new and existing objects
can determine whether the new object should replace the existing object.
safeTranslateAsyncLRUCacheget method that
takes a key and a function to call (with the key) when the key is not in the
cache. Both get and the miss function return Deferreds.
deferredLockedDeferred) in an acquire/release pair of a designated
DeferredLock. For simple functions with a static lock, this is as easy as
someLock = defer.DeferredLock()
@util.deferredLocked(someLock)
def someLockedFunction(..):
# ..
return d
for class methods which must access a lock that is an instance attribute, the lock can be specified by a string, which will be dynamically resolved to the specific instance at runtime:
def __init__(self):
self.someLock = defer.DeferredLock()
@util.deferredLocked('someLock')
def someLockedFunction(..):
# ..
return d
epoch2datetimedatetime2epochUTCdatetime.tzinfo subclass representing UTC time. A similar class has
finally been added to Python in version 3.2, but the implementation is simple
enough to include here. This is mostly used in tests to create timezeon-aware
datetime objects in UTC:
dt = datetime.datetime(1978, 6, 15, 12, 31, 15, tzinfo=UTC)