WIP on refactoring changes

pull/9248/merge
Michael DeHaan 10 years ago
parent b9223e5995
commit 6db1b4dfd2

@ -17,36 +17,14 @@
#from ansible.common.errors import AnsibleError
class MyMeta(type):
def __call__(self, *args, **kwargs):
obj = type.__call__(self, *args)
for name, value in kwargs.items():
setattr(obj, name, value)
return obj
class Attribute(object):
__metaclass__ = MyMeta
def load(self, data, base_object):
''' the loader is called to store the attribute from a datastructure when key names match. The default is very basic '''
self._validate(base_object, data)
setattr(base_object, self.name, data)
def _validate(self, data, base_object):
''' validate is called after loading an object data structure to massage any input or raise errors on any incompatibilities '''
if self.validator:
self.validator(base_object)
def post_validate(self, base_object):
''' post validate is called after templating the context of a Task (usually in Runner) to validate the types of arguments '''
if self.post_validator:
self.post_validator(base_object)
def __init__(self, isa=None, validator=None, post_validator=None):
self.isa = isa
self.validator = validator
self.post_validator = post_validator
class FieldAttribute(Attribute):
__metaclass__ = MyMeta
pass

@ -61,7 +61,8 @@ class Task(Base):
# FIXME: this should not be a Task
meta = FieldAttribute(isa='string')
name = FieldAttribute(isa='string', post_validate='_set_name')
name = FieldAttribute(isa='string', validate=self._set_name)
no_log = FieldAttribute(isa='bool')
notify = FieldAttribute(isa='list')
poll = FieldAttribute(isa='integer')
@ -103,20 +104,6 @@ class Task(Base):
''' returns a human readable representation of the task '''
return "TASK: %s" % self.get_name()
@classmethod
def load(self, block=None, role=None, data=None):
self = Task(block=block, role=role)
self._load_field_attributes(data) # from BaseObject
self._load_plugin_attributes(data) # from here, becuase of lookupPlugins
return self
def _load_plugin_attributes(self, data):
module_names = self._module_names()
for (k,v) in data.iteritems():
if k in module_names:
self.module = k
self.args = v
# ==================================================================================
# BELOW THIS LINE

Loading…
Cancel
Save