如何访问buildbot的属性变量(字典)?
我有一个buildbot属性,我相信它是一本字典。它在生成页面上的显示方式如下: 此属性由如何访问buildbot的属性变量(字典)?,buildbot,Buildbot,我有一个buildbot属性,我相信它是一本字典。它在生成页面上的显示方式如下: 此属性由提取\u fn设置,该提取返回转换为字典的字符串 我的问题是:如何作为键值对访问此属性 例如:我可以做属性('mydictionary[\'aaa\']')?这似乎不起作用。 我需要在生成步骤中访问mydictionary['aaa']。Property()函数将属性名称作为参数。 您需要允许使用任意Python代码的。 例如,写入渲染器: @util.renderer def dictionary_va
提取\u fn
设置,该提取返回转换为字典的字符串
我的问题是:如何作为键值对访问此属性
例如:我可以做属性('mydictionary[\'aaa\']')
?这似乎不起作用。
我需要在生成步骤中访问mydictionary['aaa']
。Property()函数将属性名称作为参数。
您需要允许使用任意Python代码的。
例如,写入渲染器:
@util.renderer
def dictionary_value(props):
mydictionary = props.getProperty('mydictionary')
return mydictionary['aaa']
在任何可以使用Property()或Interpolate()的地方使用函数名dictionary\u value。似乎有点晚了,但我通过谷歌链接找到了它,所以它可能会帮助其他人 要像Narayanan希望的那样存档传递的更多参数,第一种方法是使用
.withArgs
函数,如中所述
withArgs
接受*args
或*kwargs
参数,因此它非常灵活
另一种方法是使用实现IRenderable
接口并覆盖其getRenderingFor
方法的
import time
from buildbot.interfaces import IRenderable
from zope.interface import implementer
@implementer(IRenderable)
class FromDict(object):
def __init__(self, key, default = None):
self.key = key
self.default = default
def getRenderingFor(self, props):
return props.getPropety('mydictionary', {}).value(key, default)
# When used, the renderer must be initialized and
# the parameters can be passed to its constructor
ShellCommand(command=['echo', FromDict(key='aaa', default='42')])
感谢您的回复。在您定义的函数def dictionary_value()中,它使用一个名为props的标准参数。但如果我想通过我自己的论点呢?我希望将键作为参数传递,以便使用不同的键调用同一函数。Narayanan,您可以将键设置为其他属性:mydictionary=props.getProperty('mydictionary')mykey=props.getProperty('mykey')返回mydictionary[mykey]
import time
from buildbot.interfaces import IRenderable
from zope.interface import implementer
@implementer(IRenderable)
class FromDict(object):
def __init__(self, key, default = None):
self.key = key
self.default = default
def getRenderingFor(self, props):
return props.getPropety('mydictionary', {}).value(key, default)
# When used, the renderer must be initialized and
# the parameters can be passed to its constructor
ShellCommand(command=['echo', FromDict(key='aaa', default='42')])