Skip to content

Commit

Permalink
Merge pull request #120 from dagwieers/xml-prepare-upstream
Browse files Browse the repository at this point in the history
Relicense to GPLv3+ header
  • Loading branch information
cmprescott authored Jul 19, 2017
2 parents b56822c + 4af8311 commit d399f19
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions library/xml.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# xml - Manage bits and pieces of XML files
#

# Copyright 2014, Red Hat, Inc.
# Tim Bielawa <[email protected]>
# Magnus Hedemark <[email protected]>
#
# This software may be freely redistributed under the terms of the GNU
# general public license version 2.
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.


ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'],
Expand Down Expand Up @@ -95,7 +103,7 @@
choices: [ xml, yaml ]
default: yaml
requirements:
- lxml
- lxml >= 2.3.0
notes:
- This module does not handle complicated xpath expressions.
So limit xpath selectors to simple expressions.
Expand Down Expand Up @@ -587,20 +595,19 @@ def children_to_nodes(module=None, children=[], type='yaml'):
return [child_to_element(module, child, type) for child in children]


def finish(m, tree, xpath, namespaces, changed=False, msg="", hitcount=0, matches=[]):
actions = dict(xpath=xpath, namespaces=namespaces, state=m.params['state'])
def finish(module, tree, xpath, namespaces, changed=False, msg="", hitcount=0, matches=[]):
actions = dict(xpath=xpath, namespaces=namespaces, state=module.params['state'])

if not changed:
m.exit_json(changed=changed, actions=actions, msg=msg, count=hitcount, matches=matches)
module.exit_json(changed=changed, actions=actions, msg=msg, count=hitcount, matches=matches)

if m.params['path']:
xml_file = os.path.expanduser(m.params['path'])
tree.write(xml_file, xml_declaration=True, encoding='UTF-8', pretty_print=m.params['pretty_print'])
m.exit_json(changed=changed, actions=actions, msg=msg, count=hitcount, matches=matches)
if module.params['path']:
tree.write(module.params['path'], xml_declaration=True, encoding='UTF-8', pretty_print=module.params['pretty_print'])
module.exit_json(changed=changed, actions=actions, msg=msg, count=hitcount, matches=matches)

if m.params['xmlstring']:
xml_string = etree.tostring(tree, xml_declaration=True, encoding='UTF-8', pretty_print=m.params['pretty_print'])
m.exit_json(changed=changed, actions=actions, msg=msg, count=hitcount, matches=matches, xmlstring=xml_string)
if module.params['xmlstring']:
xml_string = etree.tostring(tree, xml_declaration=True, encoding='UTF-8', pretty_print=module.params['pretty_print'])
module.exit_json(changed=changed, actions=actions, msg=msg, count=hitcount, matches=matches, xmlstring=xml_string)


def decode(value):
Expand All @@ -620,8 +627,8 @@ def decode(value):
def main():
module = AnsibleModule(
argument_spec=dict(
path=dict(type='path', default='', aliases=['dest', 'file']),
xmlstring=dict(type='str', default=''),
path=dict(type='path', aliases=['dest', 'file']),
xmlstring=dict(type='str'),
xpath=dict(type='str', default='/'),
namespaces=dict(type='dict', default={}),
state=dict(type='str', default='present', choices=['absent', 'present'], aliases=['ensure']),
Expand Down

0 comments on commit d399f19

Please sign in to comment.