Merge "Automatically call MuranoPL initialize/destroy methods"
This commit is contained in:
commit
894f4595cc
@ -4,3 +4,4 @@ Name: Object
|
|||||||
|
|
||||||
Methods:
|
Methods:
|
||||||
initialize:
|
initialize:
|
||||||
|
destroy:
|
||||||
|
@ -83,6 +83,12 @@ class MuranoDslExecutor(object):
|
|||||||
raise Exception('{0} is not an action'.format(method.name))
|
raise Exception('{0} is not an action'.format(method.name))
|
||||||
# TODO (slagun): check method accessibility from murano_class
|
# TODO (slagun): check method accessibility from murano_class
|
||||||
|
|
||||||
|
if not external_call and is_special_method:
|
||||||
|
LOG.deprecated('initialize/destroy methods are called '
|
||||||
|
'automatically by engine. This call is no-op '
|
||||||
|
'and will become exception in the future')
|
||||||
|
return None
|
||||||
|
|
||||||
# restore this from upcast object (no change if there was no upcast)
|
# restore this from upcast object (no change if there was no upcast)
|
||||||
this = this.real_this
|
this = this.real_this
|
||||||
arguments_scheme = method.arguments_scheme
|
arguments_scheme = method.arguments_scheme
|
||||||
|
@ -130,14 +130,16 @@ class MuranoClass(object):
|
|||||||
return result[0]
|
return result[0]
|
||||||
|
|
||||||
def find_all_methods(self, name):
|
def find_all_methods(self, name):
|
||||||
#resolved_name = self._namespace_resolver.resolve_name(name, self.name)
|
result = []
|
||||||
if name in self._methods:
|
queue = collections.deque([self])
|
||||||
return [self.methods[name]]
|
while queue:
|
||||||
if not self._parents:
|
c = queue.popleft()
|
||||||
return []
|
if name in c.methods:
|
||||||
return list(reduce(
|
method = c.methods[name]
|
||||||
lambda x, y: x + [t for t in y if t not in x],
|
if method not in result:
|
||||||
[p.find_all_methods(name) for p in self._parents]))
|
result.append(method)
|
||||||
|
queue.extend(c.parents)
|
||||||
|
return result
|
||||||
|
|
||||||
def find_property(self, name):
|
def find_property(self, name):
|
||||||
types = collections.deque([self])
|
types = collections.deque([self])
|
||||||
|
@ -109,7 +109,8 @@ class MuranoMethod(object):
|
|||||||
return macros.MethodBlock(body)
|
return macros.MethodBlock(body)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return 'MuranoMethod({0})'.format(self.name)
|
return 'MuranoMethod({0}::{1})'.format(
|
||||||
|
self.murano_class.name, self.name)
|
||||||
|
|
||||||
def invoke(self, executor, this, parameters):
|
def invoke(self, executor, this, parameters):
|
||||||
return self.murano_class.invoke(self.name, executor, this, parameters)
|
return self.murano_class.invoke(self.name, executor, this, parameters)
|
||||||
|
@ -88,6 +88,7 @@ class ObjectStore(object):
|
|||||||
if not self.initializing:
|
if not self.initializing:
|
||||||
executor = helpers.get_executor(context)
|
executor = helpers.get_executor(context)
|
||||||
methods = obj.type.find_all_methods('initialize')
|
methods = obj.type.find_all_methods('initialize')
|
||||||
|
methods.reverse()
|
||||||
for method in methods:
|
for method in methods:
|
||||||
method.invoke(executor, obj, {})
|
method.invoke(executor, obj, {})
|
||||||
return obj
|
return obj
|
||||||
|
Loading…
Reference in New Issue
Block a user