diff options
Diffstat (limited to 'v2/ansible')
-rw-r--r-- | v2/ansible/errors/__init__.py | 2 | ||||
-rw-r--r-- | v2/ansible/parsing/__init__.py | 2 | ||||
-rw-r--r-- | v2/ansible/parsing/yaml/constructor.py | 22 | ||||
-rw-r--r-- | v2/ansible/parsing/yaml/objects.py | 17 | ||||
-rw-r--r-- | v2/ansible/playbook/helpers.py | 2 | ||||
-rw-r--r-- | v2/ansible/playbook/playbook_include.py | 2 | ||||
-rw-r--r-- | v2/ansible/playbook/role/definition.py | 2 | ||||
-rw-r--r-- | v2/ansible/playbook/task.py | 2 |
8 files changed, 22 insertions, 29 deletions
diff --git a/v2/ansible/errors/__init__.py b/v2/ansible/errors/__init__.py index 7effe41df7..bdd6e52448 100644 --- a/v2/ansible/errors/__init__.py +++ b/v2/ansible/errors/__init__.py @@ -92,7 +92,7 @@ class AnsibleError(Exception): error_message = '' try: - (src_file, line_number, col_number) = self._obj.get_position_info() + (src_file, line_number, col_number) = self._obj.ansible_pos error_message += YAML_POSITION_DETAILS % (src_file, line_number, col_number) if src_file not in ('<string>', '<unicode>') and self._show_content: (target_line, prev_line) = self._get_error_lines_from_file(src_file, line_number - 1) diff --git a/v2/ansible/parsing/__init__.py b/v2/ansible/parsing/__init__.py index f8a3e96746..75465bdfa3 100644 --- a/v2/ansible/parsing/__init__.py +++ b/v2/ansible/parsing/__init__.py @@ -146,7 +146,7 @@ class DataLoader(): err_obj = None if hasattr(yaml_exc, 'problem_mark'): err_obj = AnsibleBaseYAMLObject() - err_obj.set_position_info(file_name, yaml_exc.problem_mark.line + 1, yaml_exc.problem_mark.column + 1) + err_obj.ansible_pos = (file_name, yaml_exc.problem_mark.line + 1, yaml_exc.problem_mark.column + 1) raise AnsibleParserError(YAML_SYNTAX_ERROR, obj=err_obj, show_content=show_content) diff --git a/v2/ansible/parsing/yaml/constructor.py b/v2/ansible/parsing/yaml/constructor.py index b607f46b05..0043b8a2f0 100644 --- a/v2/ansible/parsing/yaml/constructor.py +++ b/v2/ansible/parsing/yaml/constructor.py @@ -33,23 +33,20 @@ class AnsibleConstructor(Constructor): yield data value = self.construct_mapping(node) data.update(value) - data._line_number = value._line_number - data._column_number = value._column_number - data._data_source = value._data_source + data.ansible_pos = value.ansible_pos def construct_mapping(self, node, deep=False): ret = AnsibleMapping(super(Constructor, self).construct_mapping(node, deep)) - ret._line_number = node.__line__ - ret._column_number = node.__column__ # in some cases, we may have pre-read the data and then # passed it to the load() call for YAML, in which case we # want to override the default datasource (which would be # '<string>') to the actual filename we read in if self._ansible_file_name: - ret._data_source = self._ansible_file_name + data_source = self._ansible_file_name else: - ret._data_source = node.__datasource__ + data_source = node.__datasource__ + ret.ansible_pos = (data_source, node.__line__, node.__column__) return ret @@ -58,16 +55,15 @@ class AnsibleConstructor(Constructor): # to always return unicode objects value = self.construct_scalar(node) value = to_unicode(value) - data = AnsibleUnicode(self.construct_scalar(node)) + ret = AnsibleUnicode(self.construct_scalar(node)) - data._line_number = node.__line__ - data._column_number = node.__column__ if self._ansible_file_name: - data._data_source = self._ansible_file_name + data_source = self._ansible_file_name else: - data._data_source = node.__datasource__ + data_source = node.__datasource__ + ret.ansible_pos = (data_source, node.__line__, node.__column__) - return data + return ret AnsibleConstructor.add_constructor( u'tag:yaml.org,2002:map', diff --git a/v2/ansible/parsing/yaml/objects.py b/v2/ansible/parsing/yaml/objects.py index 69f8c0968d..15850dd4f8 100644 --- a/v2/ansible/parsing/yaml/objects.py +++ b/v2/ansible/parsing/yaml/objects.py @@ -29,22 +29,19 @@ class AnsibleBaseYAMLObject: _line_number = 0 _column_number = 0 - def get_position_info(self): + def _get_ansible_position(self): return (self._data_source, self._line_number, self._column_number) - def set_position_info(self, src, line, col): + def _set_ansible_position(self, obj): + try: + (src, line, col) = obj + except (TypeError, ValueError): + raise AssertionError('ansible_pos can only be set with a tuple/list of three values: source, line number, column number') self._data_source = src self._line_number = line self._column_number = col - def copy_position_info(self, obj): - ''' copies the position info from another object ''' - assert isinstance(obj, AnsibleBaseYAMLObject) - - (src, line, col) = obj.get_position_info() - self._data_source = src - self._line_number = line - self._column_number = col + ansible_pos = property(_get_ansible_position, _set_ansible_position) class AnsibleMapping(AnsibleBaseYAMLObject, dict): ''' sub class for dictionaries ''' diff --git a/v2/ansible/playbook/helpers.py b/v2/ansible/playbook/helpers.py index 0e14720557..4277e201b7 100644 --- a/v2/ansible/playbook/helpers.py +++ b/v2/ansible/playbook/helpers.py @@ -74,7 +74,7 @@ def load_list_of_tasks(ds, block=None, role=None, task_include=None, use_handler #if 'include' in task: # cur_basedir = None # if isinstance(task, AnsibleBaseYAMLObject) and loader: - # pos_info = task.get_position_info() + # pos_info = task.ansible_pos # new_basedir = os.path.dirname(pos_info[0]) # cur_basedir = loader.get_basedir() # loader.set_basedir(new_basedir) diff --git a/v2/ansible/playbook/playbook_include.py b/v2/ansible/playbook/playbook_include.py index f7eae230f7..2e4964fce9 100644 --- a/v2/ansible/playbook/playbook_include.py +++ b/v2/ansible/playbook/playbook_include.py @@ -80,7 +80,7 @@ class PlaybookInclude(Base): # items reduced to a standard structure new_ds = AnsibleMapping() if isinstance(ds, AnsibleBaseYAMLObject): - new_ds.copy_position_info(ds) + new_ds.ansible_pos = ds.ansible_pos for (k,v) in ds.iteritems(): if k == 'include': diff --git a/v2/ansible/playbook/role/definition.py b/v2/ansible/playbook/role/definition.py index fb96a0e55f..0cb1e45760 100644 --- a/v2/ansible/playbook/role/definition.py +++ b/v2/ansible/playbook/role/definition.py @@ -66,7 +66,7 @@ class RoleDefinition(Base, Become, Conditional, Taggable): # can preserve file:line:column information if it exists new_ds = AnsibleMapping() if isinstance(ds, AnsibleBaseYAMLObject): - new_ds.copy_position_info(ds) + new_ds.ansible_pos = ds.ansible_pos # first we pull the role name out of the data structure, # and then use that to determine the role path (which may diff --git a/v2/ansible/playbook/task.py b/v2/ansible/playbook/task.py index 0f5e767486..b36c24167a 100644 --- a/v2/ansible/playbook/task.py +++ b/v2/ansible/playbook/task.py @@ -159,7 +159,7 @@ class Task(Base, Conditional, Taggable, Become): # attributes of the task class new_ds = AnsibleMapping() if isinstance(ds, AnsibleBaseYAMLObject): - new_ds.copy_position_info(ds) + new_ds.ansible_pos = ds.ansible_pos # use the args parsing class to determine the action, args, # and the delegate_to value from the various possible forms |