misc.py 文件源码

python
阅读 38 收藏 0 点赞 0 评论 0

项目:SoCFoundationFlow 作者: mattaw 项目源码 文件源码
def subst_func(tsk):
    "Substitutes variables in a .in file"

    m4_re = re.compile('@(\w+)@', re.M)

    code = tsk.inputs[0].read() #Utils.readf(infile)

    # replace all % by %% to prevent errors by % signs in the input file while string formatting
    code = code.replace('%', '%%')

    s = m4_re.sub(r'%(\1)s', code)

    env = tsk.env
    di = getattr(tsk, 'dict', {}) or getattr(tsk.generator, 'dict', {})
    if not di:
        names = m4_re.findall(code)
        for i in names:
            di[i] = env.get_flat(i) or env.get_flat(i.upper())

    tsk.outputs[0].write(s % di)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号