python - 对 buildbot 构建属性执行字符串转换?

标签 python buildbot

Interpolate 中使用属性或源标记属性之前,是否有一种好的方法对其执行字符串转换?我们在分支名称中使用斜杠,我需要将斜杠转换为破折号,以便在文件名中使用它们。

也就是说,假设我有分支“feature/fix-all-the-things”,可通过 Interpolate("%(prop:branch)s")Interpolate( “%(src::branch)s”)。我希望能够将其转换为“功能修复所有事物”以进行一些插值。显然,它需要保持原来的形式,以便从源代码管理中选择合适的分支。

最佳答案

事实证明,我只需要继承Interpolate:

import re
from buildbot.process.properties import Interpolate


class InterpolateReplace(Interpolate):
    """Interpolate with regex replacements.

    This takes an additional argument, `patterns`, which is a list of
    dictionaries containing the keys "search" and "replace", corresponding to
    `pattern` and `repl` arguments to `re.sub()`.
    """
    def __init__(self, fmtstring, patterns, *args, **kwargs):
        Interpolate.__init__(self, fmtstring, *args, **kwargs)
        self._patterns = patterns

    def _sub(self, s):
        for pattern in self._patterns:
            search = pattern['search']
            replace = pattern['replace']
            s = re.sub(search, replace, s)
        return s

    def getRenderingFor(self, props):
        props = props.getProperties()
        if self.args:
            d = props.render(self.args)
            d.addCallback(lambda args:
                          self._sub(self.fmtstring % tuple(args)))
            return d
        else:
            d = props.render(self.interpolations)
            d.addCallback(lambda res:
                          self._sub(self.fmtstring % res))
            return d

关于python - 对 buildbot 构建属性执行字符串转换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28634959/

相关文章:

python - VS Code Jupyter Notebook Run Cell 前进到下一个

python 2.6 异常.TypeError : unbound method _init_() ESMTP client instance

java - 有没有办法测试是否有人使用 JGit 从本地存储库推送到远程存储库?

python - 使用 NLTK 删除停用词

python - 如果 Jinja2 没有小数值,如何四舍五入为零小数?

python - 在 linux 上,如何允许任何用户写入文件,但只能通过运行我的(python)脚本?

python - 没有越界和裁剪值的 Numpy 二维数组索引

git 提交队列工具

continuous-integration - 为多个项目设置 Buildbot 托管服务

linux - buildbot 安装 : git poll failed