00001 """
00002 parse a dict or SCons.Environment object and update the slimvars
00003 """
00004
00005 __copyright__ = """
00006 Copyright 2008 Sean Ross-Ross
00007 """
00008 __license__ = """
00009 This file is part of SLIMpy .
00010
00011 SLIMpy is free software: you can redistribute it and/or modify
00012 it under the terms of the GNU Lesser General Public License as published by
00013 the Free Software Foundation, either version 3 of the License, or
00014 (at your option) any later version.
00015
00016 SLIMpy is distributed in the hope that it will be useful,
00017 but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 GNU Lesser General Public License for more details.
00020
00021 You should have received a copy of the GNU Lesser General Public License
00022 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>.
00023 """
00024
00025 from slimpy_base.Environment.InstanceManager import InstanceManager
00026 from slimpy_base.setup.DEFAULTS import DEFAULTS
00027
00028 __env__ = InstanceManager()
00029
00030
00031
00032 def parse_env( env, *E, **kw ):
00033 """
00034 updates 'slimvars' class with values from
00035 env that are also in 'DEFAULTS' retuns
00036 a dict with values from *E, **kw and updated
00037 with the values from env that are not in
00038 'DEFAULTS'
00039
00040 @param env:
00041 @type env: dict or SCons.Environment
00042 """
00043
00044 log = __env__['record'](1, 'stat' )
00045
00046 print >> log, "SLIMpy: Building AST"
00047
00048 __env__.assure_new_instances( )
00049
00050 if hasattr(env, "Dictionary" ):
00051 e_dict = env.Dictionary()
00052 else:
00053 e_dict = dict( env )
00054
00055
00056
00057 ret_env = dict(*E, **kw)
00058
00059 n_dict= {}
00060
00061 for key in DEFAULTS.iterkeys():
00062 if key in e_dict:
00063 n_dict[key] = e_dict[key]
00064
00065 __env__['slimvars'].setglobal( **n_dict )
00066
00067 callbacks = e_dict.pop( 'callbacks' ,[])
00068
00069
00070 for func in callbacks:
00071 if isinstance(func, str):
00072 import function_callbacks
00073 func = getattr( function_callbacks, func )
00074
00075 func( )
00076
00077 ret_env.update( e_dict )
00078
00079 return ret_env