#! /usr/bin/env python """ Read/write configuration params from system configuration file initial.rdf """ __author__ = "Anand B Pillai" __maintainer__ = "Anand B Pillai" __version__ = "$Id: config.py 1974 2006-08-28 20:50:05Z abp $" import sys, os import xml.dom.minidom as mdom def get_system_config(): for f in ('initial.rdf', os.path.abspath(os.path.join(sys.prefix, 'initial.rdf'))): if os.path.isfile(f): return f def parse_system_config(): """ Parse system config file and return a DOM object """ f = get_system_config() try: dom = mdom.parse(f) return dom except Exception, e: print e def get_elem_data(name): """ Get the value (PCDATA) of element given by 'name' """ dom = parse_system_config() elems = dom.getElementsByTagName('eiao:' + name) # Take only first if elems: elem = elems[0] textElem = elem.firstChild return str(textElem.data) return ''