summaryrefslogtreecommitdiffstats
path: root/files
diff options
context:
space:
mode:
authorJames Shubin <james@shubin.ca>2012-07-27 20:15:13 -0400
committerJames Shubin <james@shubin.ca>2012-07-27 20:15:13 -0400
commit35830b0a11565c3e2e188cd258bea7da27f735fe (patch)
treef5f27a1daa551652ac0c555ea799ced27bdff972 /files
parent35b338115cef478ed2baa1f4ca16e3652b45de7b (diff)
downloadpuppet-gluster-35830b0a11565c3e2e188cd258bea7da27f735fe.tar.gz
puppet-gluster-35830b0a11565c3e2e188cd258bea7da27f735fe.tar.xz
puppet-gluster-35830b0a11565c3e2e188cd258bea7da27f735fe.zip
Forgot to add the xml.py parser.
Diffstat (limited to 'files')
-rw-r--r--files/xml.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/files/xml.py b/files/xml.py
new file mode 100644
index 0000000..de13895
--- /dev/null
+++ b/files/xml.py
@@ -0,0 +1,39 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+# Copyright (C) 2012 James Shubin <james@shubin.ca>
+# Copyright (C) 2012 Jordi GutiƩrrez Hermoso <jordigh@octave.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# thanks to Jordi for fighting with the xml for me so that I didn't have to :)
+
+# EXAMPLE:
+# $ gluster volume --xml info <VOLNAME> | ./xml.py <KEY>
+# <VALUE>
+
+import sys
+import lxml.etree as etree
+
+if len(sys.argv) != 2:
+ sys.exit(1)
+
+t = etree.parse(sys.stdin)
+r = t.getroot()
+v = [x.find('value').text for x in r.findall('.//option') if x.find('name').text == str(sys.argv[1])]
+if len(v) == 1:
+ print v[0]
+ sys.exit(0)
+else: # more than one value found
+ sys.exit(1)
+