def get_sample_xml_string(): """ @return: a multi line xml string representing a L{DirectProteinMixture}. """ root = ET.Element('model') mutation = ET.SubElement(root, 'mutation') mutation.set('kappa', '2.0') distribution = ET.SubElement(mutation, 'distribution') for nt in nt_ordered: node = ET.SubElement(distribution, 'nt') node.set('symbol', nt) node.set('weight', '1.0') selection = ET.SubElement(root, 'selection') for i in range(3): category = ET.SubElement(selection, 'category') category.set('weight', '3.0') for aa in aa_ordered: node = ET.SubElement(category, 'aa') node.set('symbol', aa) node.set('energy', '2.0') # modify the contents so that the tree is shown as indented XmlUtil.indent(root) # get the string representing the tree tree = ET.ElementTree(root) out = StringIO() tree.write(out) return out.getvalue()
def get_sample_xml_string(): """ @return: a multi line xml string """ # define the model kappa = 2 category_weights = [1, 4, 5] nt_weights_list = [[1, 4, 4, 1], [2, 3, 3, 2], [1, 1, 1, 1]] # create the model using the definition root = ET.Element("model") root.set("kappa", str(float(kappa))) for category_weight, nt_weights in zip(category_weights, nt_weights_list): category = ET.SubElement(root, "category") category.set("weight", str(float(category_weight))) distribution = ET.SubElement(category, "distribution") for nt, weight in zip(list("ACGT"), nt_weights): terminal = ET.SubElement(distribution, "nt") terminal.set("symbol", nt) terminal.set("weight", str(float(weight))) # modify the contents so that the tree is shown as indented XmlUtil.indent(root) # get the string representing the tree tree = ET.ElementTree(root) out = StringIO() tree.write(out) return out.getvalue()
def get_sample_xml_string(): """ @return: a multi line xml string """ # define the model kappa = 2 category_weights = [1, 4, 5] nt_weights_list = [[1, 4, 4, 1], [2, 3, 3, 2], [1, 1, 1, 1]] # create the model using the definition root = ET.Element('model') root.set('kappa', str(float(kappa))) for category_weight, nt_weights in zip(category_weights, nt_weights_list): category = ET.SubElement(root, 'category') category.set('weight', str(float(category_weight))) distribution = ET.SubElement(category, 'distribution') for nt, weight in zip(list('ACGT'), nt_weights): terminal = ET.SubElement(distribution, 'nt') terminal.set('symbol', nt) terminal.set('weight', str(float(weight))) # modify the contents so that the tree is shown as indented XmlUtil.indent(root) # get the string representing the tree tree = ET.ElementTree(root) out = StringIO() tree.write(out) return out.getvalue()
def loadString(xmlstr, xlist=True): """加载字符串 xmlstr 字符串 xlist 重复的xpath合并成list """ global _ENCODING_ dom = XmlUtil.parseString(xmlstr) data = XmlUtil.domToDict(dom, _ENCODING_, xlist=xlist) dom.unlink() loadData_(data, '', xlist)
def loadFile(fname, xlist=True): """加载文件 fname 文件名 xlist 重复的xpath合并成list """ if _FILES_.has_key(fname): return 0 global _ENCODING_ dom = XmlUtil.parseFile(fname) data = XmlUtil.domToDict(dom, _ENCODING_, xlist=xlist) dom.unlink() loadData_(data, '', xlist) _FILES_[fname] = xlist return 1
def test_serialization(self): """ Verify that serialization and deserialization works. """ # create the mixture model input_xml_string = get_sample_xml_string() mixture_model = deserialize_mixture_model(input_xml_string) # create an xml string from the mixture model element_tree = mixture_model.to_element_tree() XmlUtil.indent(element_tree.getroot()) out = StringIO() element_tree.write(out) output_xml_string = out.getvalue() # verify that the xml string we get out is the same as the one we put in self.assertEquals(input_xml_string, output_xml_string)
def creTmpTab(auth, tabname, array=[]): dbType, conn = DBConnect.getConnect(auth) colarray = [] # 暂时只处理ORACLE if dbType == 'ORACLE': log.info('DB type is ORACLE, Start get columns') sql = XmlUtil.dbExeSQL('COLUMN') sqlformat = sql.format(tabname=tabname) result = RunSQL.runSQL(conn, sqlformat) # 数据处理 for i in array: for j in result: if i in j[0]: colarray.append(j[0].split(',')[0]) crecol = ','.join(colarray) tab = 'COMM_TMP' sql = 'CREATE TABLE %s (%s)' % (tab, crecol) result_cnt = RunSQL.runSQL( DBConnect.getConnect(auth)[1], "select count(1) from user_tables where table_name ='%s'" % tab) if result_cnt[0][0] == 0: log.info('%s not exists' % tab) RunSQL.ddlSQL(DBConnect.getConnect(auth)[1], sql) log.info('Create table successful') else: RunSQL.ddlSQL( DBConnect.getConnect(auth)[1], 'delete from %s' % tab) log.info('Delete table successful') RunSQL.ddlSQL(DBConnect.getConnect(auth)[1], 'drop table %s' % tab) log.info('Drop table successful') RunSQL.ddlSQL(DBConnect.getConnect(auth)[1], sql) log.info('Create table successful')
def CommTab(srcauth, trgauth, tabname, tmptab, array=[]): data = [] for i in array: c = 's.%s = t.%s' % (i, i) data.append(c) condition = ' and '.join(data) sql = XmlUtil.dbExeSQL('TMP') sqlformat = sql.format(srcname=tabname, trgname=tmptab, condition=condition) flag = RunSQL.runSQL(DBConnect.getConnect(trgauth)[1], sqlformat) # print (sqlformat) if len(flag) == 0: log.info('Compare Current compare data PK structure same in becompare') log.info('Start check table attribute') sql = XmlUtil.dbExeSQL('TRG_EXISTS') sqlformat = sql.format(srcname=tabname, trgname=tmptab, condition=condition) # print(sqlformat) becompare = RunSQL.runSQL(DBConnect.getConnect(trgauth)[1], sqlformat) # sql = XmlUtil.dbExeSQL('TRG_NOT_EXISTS') # sqlformat = sql.format(srcname=srcname, trgname=trgname, condition=condition) # print(sqlformat) # becompare2 = RunSQL.runSQL(DBConnect.getConnect(trgauth)[1], sqlformat) return [becompare, ''] else: log.info( 'Compare Current compare data PK structure different in becompare ,%s PK more then %s' % (tmptab, tabname)) # print(array, flag) sql = XmlUtil.dbExeSQL('TRG_EXISTS') sqlformat = sql.format(srcname=tabname, trgname=tmptab, condition=condition) # print(sqlformat) becompare = RunSQL.runSQL(DBConnect.getConnect(trgauth)[1], sqlformat) cond = [] for i in range(0, len(array)): c = "{key} = '{value}'".format(key=array[i], value=flag[0][i]) cond.append(c) conds = ' and '.join(cond) sql = 'select * from {tabname} where {condition}'.format( tabname=tabname, condition=conds) val_com = RunSQL.runSQL(DBConnect.getConnect(srcauth)[1], sql) return [becompare, val_com]
def getPKColumn(auth, tabname): dbType, conn = DBConnect.getConnect(auth) # 暂时只处理ORACLE if dbType == 'ORACLE': log.info('DB type is ORACLE, Start get constraints...') sql = XmlUtil.dbExeSQL('CONSTRAINT') sqlformat = sql.format(tabname=tabname) result = RunSQL.runSQL(conn, sqlformat) # 数据处理 array = [] for j in result: detail = j[1].split(',') for k in detail: if 'P_' in k: array.append(k.split('_')[1]) return array
def columnComm(tabname, path): log.info('Start to check table column name and type ..') dbrange = ['SCOTT_10.45.15.201', 'SCOTT_10.45.15.205'] # 后期改成入参 dict = {} for i in dbrange: dbType, conn = DBConnect.getConnect(i) # 暂时只处理ORACLE if dbType == 'ORACLE': log.info('DB type is ORACLE, Start get columns...') sql = XmlUtil.dbExeSQL('COLUMN') sqlformat = sql.format(tabname=tabname) result = RunSQL.runSQL(conn, sqlformat) # 数据处理 array = [] for j in result: array.append(j[0]) dict[i] = array # return dict commpare(path, '字段', dict)
def constComm(tabname, path): log.info('Start to check table constraint ..') dbrange = ['SCOTT_10.45.15.201', 'SCOTT_10.45.15.205'] # 后期改成入参 dict = {} for i in dbrange: dbType, conn = DBConnect.getConnect(i) # 暂时只处理ORACLE if dbType == 'ORACLE': log.info('DB type is ORACLE, Start get constraints...') sql = XmlUtil.dbExeSQL('CONSTRAINT') sqlformat = sql.format(tabname=tabname) result = RunSQL.runSQL(conn, sqlformat) # 数据处理 array = [] for j in result: detail = j[0] + '@' + j[1] array.append(detail) dict[i] = array # return dict commpare(path, '约束', dict)
if __name__ == '__main__': configPath = sys.argv[1] #print(sys.path) if configPath.startswith("./"): configPath = os.path.join(FileUtil.getEntryFilePath(), configPath[2:]) elif ":" in configPath or configPath.startswith("/"): print("configPath = %s" % (configPath)) else: configPath = os.path.join(sys.path[1], configPath) try: jsonDict = ConfigManager.loadConfig(configPath) ConfigManager.setGlobalConfig(jsonDict) filePath = ConfigManager.getValue(ConfigManager.key_project_file_path) domTree, rootNode = XmlUtil.readXML(filePath) destDllDir = "./TempDir" localDir = ConfigManager.getValue(ConfigManager.key_project_local_dir) repoType = ConfigManager.getValue( ConfigManager.key_project_repository_type) #目前仅支持git repoRemote = ConfigManager.getValue( ConfigManager.key_project_repository_address) branchName = ConfigManager.getValue( ConfigManager.key_project_branch_name) buildLogFile = ConfigManager.getValue( ConfigManager.key_project_build_log_file) reportLevels = ConfigManager.getValue( ConfigManager.key_project_report_level) reportKeys = ConfigManager.getValue( ConfigManager.key_project_report_keys)
def loadFile(fname): global _ENCODING_ dom = XmlUtil.parseFile(fname) data = XmlUtil.domToDict(dom, _ENCODING_) dom.unlink() loadData_(data, '')