开发者

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

开发者 https://www.devze.com 2023-03-23 05:19 出处:网络
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.

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 = '开发者_JAVA百科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 ?


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 !
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号