Scons (Build System) Variables : load config file with custom/unknown values

白昼怎懂夜的黑 提交于 2019-12-13 02:52:07

问题


I have a trouble with Scons.Variables. I want to use config files with custom keys and values. My idea to load config files with keys and values and use it with SubstFile method. For example (rough code) :

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)

But vars.UnknownVariables() return empty list. My test template file :

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

And vars.UknownVariables() called :

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

May be somebody try to implement something like this and can give some advances ?


回答1:


I not found neeeded tools in Scons, but Python is great (i newbie in python now, few days studing only).

Google give me some useful links, such as SimpleConfigParser (i use method from CustomParser)

Implement it is very easy and i got what i need :

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

Content of config.cfg.in file :

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

Emulator mode %emulate%

Thanks for using Avina !

Content of template.conf file :

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

And result file :

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

Emulator mode 'no'

Thanks for using Avina !


来源:https://stackoverflow.com/questions/6815754/scons-build-system-variables-load-config-file-with-custom-unknown-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!