[Buildbot-devel] Using dictionaries with WithProperties objects

Nicolas Alvarez nicolas.alvarez at gmail.com
Tue Dec 29 23:11:02 UTC 2009


Dustin J. Mitchell wrote:
> Nicolas: Python syntax really prevents what you want to see, unless we
> introduce PropertyKeyedDict, PropertyKeyedList, etc., which seems like
> overkill.  If your properties uses are this complex, just use a custom
> step - as you can see above, it's pretty easy.

All we need is a DeferredString class you can put anywhere you currently can 
use WithProperties (eg. a ShellCommand's "command" property). That 
DeferredString would have its evaluate() method called at build time, 
returning a string.

It would be a generalization of WithProperties. WithProperties could be a 
subclass of DeferredString that implements evaluate() by calling getProperty 
on the build object.

There could be a SimpleDeferredString subclass taking take a function in the 
constructor (or maybe do this in the default impl of DeferredString):

class SimpleDeferredString(DeferredString):
    def __impl__(self, func):
        self.func = func
    def evaluate(self, step):
        f = self.func
        return f(step)

so you could do this:

f.addStep(ShellCommand(
    command=["tar", "czf",
        SimpleDeferredString(lambda step: d[step.getProperty("foo")]),
        "source"]
))

so you don't even have to create a DictionaryLookupDeferredString subclass 
in the master.cfg.

-- 
Nicolas

(I read mailing lists through Gmane. Please don't Cc me on replies; it makes 
me get one message on my newsreader and another on email.)





More information about the devel mailing list