Scons(构建系统)变量:使用自定义/未知值加载配置文件

时间:2011-07-25 11:59:32

标签: variables config scons

我遇到了Scons.Variables的问题。我想使用配置文件与自定义键和值。我的想法是使用键和值加载配置文件,并将其与SubstFile方法一起使用。 例如(粗略代码):

vars = Variables('templateValues.conf')
vars_dict = vars.UnknownVariables().keys() # bad code, need something to convert vars to Python dictionary
env.Substfile('myconfig.cfg.in', SUBST_DICT = vars_dict)

但是vars.UnknownVariables()返回空列表。 我的测试模板文件:

version = 105
mode = 'release'
source = 'database'
emulate = 'no'

vars.UknownVariables()调用:

vars = Variables('templateValues.conf')
print vars.UnknownVariables().keys()
# []

可能有人试图实现这样的事情,并可以取得一些进展吗?

1 个答案:

答案 0 :(得分:0)

我没有在Scons中找到需要的工具,但Python很棒(我现在在python中新手,几天只研究)。

Google为我提供了一些有用的链接,例如SimpleConfigParser(我使用CustomParser中的方法)

实施它很容易,我得到了我需要的东西:

Import('env')
templVars = parse_config('template.conf')
varEnv = env.Clone(tools = ['textfile', 'default'])
varEnv.Substfile('config.cfg.in', SUBST_DICT = templVars)

config.cfg.in文件的内容:

this is simple text with template values
Version is %version%
Build mode is %mode%

Emulator mode %emulate%

Thanks for using Avina !

template.conf文件的内容:

%version% = 105
%mode% = 'test1'
%source% = 'database'
%emulate% = 'no'

结果文件:

this is simple text with template values
Version is 105
Build mode is 'test1'

Emulator mode 'no'

Thanks for using Avina !
相关问题