def parseTools(self): """parse the xml file and generate sql file""" try: analytics_tools = Parser.getNodeTag(self, self.xmlDoc, "analytics_tools") atList = Parser.getNodeList(self, analytics_tools, "analytics_tool") for at in atList: atDic = {} name = Parser.getNodeVal(self, at, "name") kind = Parser.getNodeVal(self, at, "kind") if kind.lower() in( "greenplum", "postgres"): atDic["name"] = Parser.getNodeVal(self, at, "name") atDic["kind"] = Parser.getNodeVal(self, at, "kind") atDic["host"] = Parser.getNodeVal(self, at, "host") atDic["port"] = Parser.getNodeVal(self, at, "port") atDic["superuser"] = Parser.getNodeVal(self, at, "superuser") atDic["database"] = Parser.getNodeVal(self, at, "database") atDic["username"] = Parser.getNodeVal(self, at, "user") atDic["master_dir"] = Parser.getNodeVal(self, at, "master_dir") atDic["env"] = Parser.getNodeVal(self, at, "env") self.analyticsTools[name] = atDic except Exception, exp: print str(exp) print "Error when parsing analyticsTools" sys.exit()
def __createToolsTb(self): """create the analytics tool table""" # drop table stmt stmt = "DROP TABLE IF EXISTS " + self.analyticsToolTb + " cascade;\n\n" self.sqlFileHd.write(stmt) analytics_tools = Parser.getNodeTag(self, self.xmlDoc, "analytics_tools") metadata = Parser.getNodeTag(self, analytics_tools, "metadata") colList = Parser.getNodeList(self, metadata, "column") for col in colList: colName = Parser.getNodeVal(self, col, "name") colType = Parser.getNodeVal(self, col, "type") self.colsDesc[colName] = colType # convert dict cols = self.dicToArray(self.colsDesc) # create table stmt stmt = "CREATE TABLE " + self.analyticsToolTb + "(" stmt = stmt + ','.join(cols) + ");\n\n" self.sqlFileHd.write(stmt)