Skip to content

Instantly share code, notes, and snippets.

@bgulla
Created October 1, 2014 21:02
Show Gist options
  • Save bgulla/c076675ae22ee72b4944 to your computer and use it in GitHub Desktop.
Save bgulla/c076675ae22ee72b4944 to your computer and use it in GitHub Desktop.
Simple Hadoop Configuration Parser. For when you don't have enough time to scroll.
#!/usr/bin/python
from xml.dom import minidom
def getNodeText(node):
nodelist = node.childNodes
result = []
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
result.append(node.data)
return ''.join(result)
def parse_hadoop_conf(filename):
doc_vals = {}
xmldoc = minidom.parse(filename)
itemlist = xmldoc.getElementsByTagName('property')
for s in itemlist :
n_name = getNodeText(s.getElementsByTagName('name')[0])
n_value = getNodeText(s.getElementsByTagName('value')[0])
doc_vals[n_name] = n_value
print filename
for item in doc_vals.keys():
print "\t\t", item, "\t=>\t", doc_vals[item]
parse_hadoop_conf("mapred-site.xml")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment