import xml.etree.ElementTree as XMLParser class XMLSetup (object): """XML Setup Parser""" __tree = None # Parser __dbType = None # database connection required: PgSQLConnection __dbConnectionRaw = None # Connection string in raw __dbConnectionStr = None # Connection string to use in sql object connection def __init__(self, filename): """Parse the file in the constructor""" self.__tree = XMLParser.parse(filename) def __del__(self): """Destructor do nothing""" pass def getdbConnectionStr(self): """XML to database connection string""" if self.__dbConnectionRaw is not None: return self.__dbConnectionRaw for element in self.__tree.iter('db'): self.__dbConnectionRaw = element.attrib self.__dbType = self.__dbConnectionRaw['type'] if self.__dbType == "PgSQLConnection": self.__dbConnectionStr = self.getPostgresConnectionStr() return self.__dbConnectionStr return None def getPostgresConnectionStr(self): """aaaaa""" str = self.__dbConnectionRaw del str['type'] return str def getMysqlConnectionStr (self): """aaaaa""" pass def getBoard(self, key, default): for element in self.__tree.iter('board'): if key in element.attrib: return element.attrib[key] return default