3737from mig .shared .fileio import unpickle
3838
3939
40- _RUNTIME_ASSISTANTS = {
41- 'send_email' : None ,
42- }
43-
44-
45- def default_runtime_assistants ():
46- runtime_services = dict (_RUNTIME_ASSISTANTS )
47-
48- from mig .shared .notification import send_email
49- runtime_services ['send_email' ] = send_email
50-
51- return runtime_services
52-
53-
5440class RuntimeConfiguration :
5541 """A proxy object to be passed in-place of a Configuration which can be
5642 extended with information relevant only at runtime.
@@ -66,9 +52,9 @@ class RuntimeConfiguration:
6652 to callers without being mixed in with the statuc data.
6753 """
6854
69- def __init__ (self , configuration , assistants ):
55+ def __init__ (self , configuration ):
7056 object .__setattr__ (self , '_configuration' , configuration )
71- object .__setattr__ (self , '_assistants ' , assistants )
57+ object .__setattr__ (self , '_context ' , {} )
7258
7359 def __delattr__ (self , attr ):
7460 return setattr (self ._configuration , attr )
@@ -79,28 +65,11 @@ def __getattr__(self, attr):
7965 def __setattr__ (self , attr , value ):
8066 return setattr (self ._configuration , attr , value )
8167
82- def get_assistant (self , assistant_name ):
83- return self ._assistants [assistant_name ]
84-
85- def send_email (self , * args , ** kwargs ):
86- send_email = self ._assistants ['send_email' ]
87- return send_email (self , * args , ** kwargs )
88-
89- @classmethod
90- def create (cls , configuration , assistants ):
91- supplied_assistants = set (assistants .keys ())
92- expected_assistants = set (_RUNTIME_ASSISTANTS .keys ())
93-
94- missing_assistants = expected_assistants - supplied_assistants
95- if missing_assistants :
96- raise RuntimeError ('missing runtime assistants: %s'
97- % (missing_assistants ,))
98-
99- return cls (configuration , assistants )
68+ def context_get (self , context_key ):
69+ return self ._context .get (context_key , None )
10070
101- @staticmethod
102- def default_assistants ():
103- return default_runtime_assistants ()
71+ def context_set (self , context_key , context_value ):
72+ self ._context [context_key ] = context_value
10473
10574
10675def get_configuration_object (config_file = None ,
@@ -135,8 +104,7 @@ def get_configuration_object(config_file=None,
135104 if raw :
136105 return configuration
137106
138- assistants = RuntimeConfiguration .default_assistants ()
139- return RuntimeConfiguration (configuration , assistants )
107+ return RuntimeConfiguration (configuration )
140108
141109
142110def get_resource_configuration (resource_home , unique_resource_name ,
0 commit comments