From 6db1b4dfd217c8968c8fed323daf8a74340fd10f Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Fri, 3 Oct 2014 15:25:21 -0400 Subject: [PATCH] WIP on refactoring changes --- .../inventory_test_data/inventory_api.py | 0 test/v2/playbook/{task.py => test_task.py} | 0 v2/ansible/playbook/attribute.py | 30 +++---------------- v2/ansible/playbook/base.py | 2 +- v2/ansible/playbook/task.py | 17 ++--------- 5 files changed, 7 insertions(+), 42 deletions(-) mode change 100644 => 100755 test/units/inventory_test_data/inventory_api.py rename test/v2/playbook/{task.py => test_task.py} (100%) diff --git a/test/units/inventory_test_data/inventory_api.py b/test/units/inventory_test_data/inventory_api.py old mode 100644 new mode 100755 diff --git a/test/v2/playbook/task.py b/test/v2/playbook/test_task.py similarity index 100% rename from test/v2/playbook/task.py rename to test/v2/playbook/test_task.py diff --git a/v2/ansible/playbook/attribute.py b/v2/ansible/playbook/attribute.py index ae1edea943..b064406af7 100644 --- a/v2/ansible/playbook/attribute.py +++ b/v2/ansible/playbook/attribute.py @@ -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 diff --git a/v2/ansible/playbook/base.py b/v2/ansible/playbook/base.py index 9c2ad358c4..8bc9a83bd3 100644 --- a/v2/ansible/playbook/base.py +++ b/v2/ansible/playbook/base.py @@ -34,4 +34,4 @@ class Base(object): for attribute in self.attributes: attribute.validate(self) - + diff --git a/v2/ansible/playbook/task.py b/v2/ansible/playbook/task.py index 4767c95106..6c7d93f9fd 100644 --- a/v2/ansible/playbook/task.py +++ b/v2/ansible/playbook/task.py @@ -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