Skip to content

Commit d399f19

Browse files
authored
Merge pull request #120 from dagwieers/xml-prepare-upstream
Relicense to GPLv3+ header
2 parents b56822c + 4af8311 commit d399f19

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

library/xml.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
#!/usr/bin/python
22
# -*- coding: utf-8 -*-
3-
#
4-
# xml - Manage bits and pieces of XML files
5-
#
3+
64
# Copyright 2014, Red Hat, Inc.
75
# Tim Bielawa <tbielawa@redhat.com>
86
# Magnus Hedemark <mhedemar@redhat.com>
97
#
10-
# This software may be freely redistributed under the terms of the GNU
11-
# general public license version 2.
8+
# This file is part of Ansible
9+
#
10+
# Ansible is free software: you can redistribute it and/or modify
11+
# it under the terms of the GNU General Public License as published by
12+
# the Free Software Foundation, either version 3 of the License, or
13+
# (at your option) any later version.
14+
#
15+
# Ansible is distributed in the hope that it will be useful,
16+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
# GNU General Public License for more details.
1219
#
1320
# You should have received a copy of the GNU General Public License
14-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
22+
1523

1624
ANSIBLE_METADATA = {'metadata_version': '1.0',
1725
'status': ['preview'],
@@ -95,7 +103,7 @@
95103
choices: [ xml, yaml ]
96104
default: yaml
97105
requirements:
98-
- lxml
106+
- lxml >= 2.3.0
99107
notes:
100108
- This module does not handle complicated xpath expressions.
101109
So limit xpath selectors to simple expressions.
@@ -587,20 +595,19 @@ def children_to_nodes(module=None, children=[], type='yaml'):
587595
return [child_to_element(module, child, type) for child in children]
588596

589597

590-
def finish(m, tree, xpath, namespaces, changed=False, msg="", hitcount=0, matches=[]):
591-
actions = dict(xpath=xpath, namespaces=namespaces, state=m.params['state'])
598+
def finish(module, tree, xpath, namespaces, changed=False, msg="", hitcount=0, matches=[]):
599+
actions = dict(xpath=xpath, namespaces=namespaces, state=module.params['state'])
592600

593601
if not changed:
594-
m.exit_json(changed=changed, actions=actions, msg=msg, count=hitcount, matches=matches)
602+
module.exit_json(changed=changed, actions=actions, msg=msg, count=hitcount, matches=matches)
595603

596-
if m.params['path']:
597-
xml_file = os.path.expanduser(m.params['path'])
598-
tree.write(xml_file, xml_declaration=True, encoding='UTF-8', pretty_print=m.params['pretty_print'])
599-
m.exit_json(changed=changed, actions=actions, msg=msg, count=hitcount, matches=matches)
604+
if module.params['path']:
605+
tree.write(module.params['path'], xml_declaration=True, encoding='UTF-8', pretty_print=module.params['pretty_print'])
606+
module.exit_json(changed=changed, actions=actions, msg=msg, count=hitcount, matches=matches)
600607

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

605612

606613
def decode(value):
@@ -620,8 +627,8 @@ def decode(value):
620627
def main():
621628
module = AnsibleModule(
622629
argument_spec=dict(
623-
path=dict(type='path', default='', aliases=['dest', 'file']),
624-
xmlstring=dict(type='str', default=''),
630+
path=dict(type='path', aliases=['dest', 'file']),
631+
xmlstring=dict(type='str'),
625632
xpath=dict(type='str', default='/'),
626633
namespaces=dict(type='dict', default={}),
627634
state=dict(type='str', default='present', choices=['absent', 'present'], aliases=['ensure']),

0 commit comments

Comments
 (0)