def main(): allTsFile = et.getFileName(tsFile, ["ts"], []) allExmlFile = et.getFileName(exmlFile, ["exml"], []) tsIDIdx = 1231 xmlIDIdx = 729 xml_t = {} for xml in allExmlFile: line = "" with open(xml, 'r') as f: line = f.read() #line = line.replace(EXMLTRANSLATESTR, "xmlList_") #用两点 拆分 如果有中文 / 如果 有 19... 说明有问题 打印出来 没有直接替换 dd = line.split('"') for i in range(len(dd)): if i % 2 != 0: s = dd[i] if et.isIncludeChinese(s): if s.find(EXMLTRANSLATESTR) > -1: print("文件有问题 = >" + xml, "s = >" + s) else: k = getTableKey(xml_t, s) # 是否已经换过的值 if k: _k = k.replace("_", "") else: xml_t["_" + str(xmlIDIdx)] = s _k = xmlIDIdx xmlIDIdx = xmlIDIdx + 1 print("xmlID = > ", _k, "replace Str = > ", s, "file = >" + xml) line = line.replace( s, str(EXMLTRANSLATESTR + str(_k))) # strList = et.getChineseStr(line) # if len(strList) > 0: # for s in strList: # k = getTableKey(xml_t, s) # # 是否已经换过的值 # _k = 0 # if k: # _k = k.replace("_","") # else: # xml_t["_"+str(xmlIDIdx) ] = s # _k = xmlIDIdx # xmlIDIdx = xmlIDIdx+1 # print("xmlID = > ", _k, "replace Str = > ", s) # line = line.replace(s, str(EXMLTRANSLATESTR + str(_k) )) with open(xml, 'w') as f: f.write(line)
def printDiffFunc(fileMore): global insertCount fp, fn = os.path.split(fileMore) li = '' l = '' with open(fileMore, 'r') as f: li = f.read() l = li # 通过 string 分割 然后 只取 奇数的部分 里面只有内容 并且 包括lbl text allSp = l.split("string") allStr = [] for s in range(len(allSp)): if s % 2 == 1: allStr.append(allSp[s].replace("</", "").replace(">", "").replace( "\n", "").replace("\t", "")) chineseList = [] for s in allStr: if et.isIncludeChinese(s): chineseList.append(s) #chineseList = et.getChineseStr(l) if len(chineseList) > 0: for ch in chineseList: needDe = False for p in ex: if ch.find(p) > -1: needDe = True if needDe: continue id = getIdFormData(allCoffeeData, ch) isHasData = True if not id: isHasData = False id = getMaxID(allCoffeeData) + 1 # 做替换 if (">" + ch + "<") in l or ((">" + ch + "\n<") in l): l = l.replace(ch, "ccbList_" + str(id)) if not isHasData: # insert print("need insert id = >> " + str(id)) isInsertedID = getInsterIdx(needInsert, ch) if isInsertedID == None: needInsert.append({"Id": id, "ch": ch, "file": fn}) insertCount = insertCount + 1 else: dat = needInsert[isInsertedID] if fn in dat["file"]: fileName = dat["file"] else: fileName = dat["file"] + ";" + fn needInsert[isInsertedID] = { "Id": dat["Id"], "ch": dat["ch"], "file": fileName } # et.processSql() print("file = >> " + fileMore) print(ch) with open(fileMore, 'w') as ff: ff.writelines(l)