问题
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