database_tools中新增比较两个git commit的json文件的不同的功能gitdiff
This commit is contained in:
parent
a460e40db6
commit
0d11f2b68b
|
|
@ -1882,7 +1882,23 @@ def UnitRectoMetadataText(data): #把data中的单元对应变为metadata.txt中
|
|||
output += f"{units}\n\n"
|
||||
return output
|
||||
|
||||
def gitdiff(commitid1,commitid2,fileinrepo="题库0.3/Problems.json",tempfilepath = "临时文件/temp.json"): # 根据两个git 的commit id 比较某一个json文件的不同, 返回一个tuple, 第一项是新增key的变化, 第二项是同一个key下哪些字段变化了
|
||||
os.system(f"git show {commitid1}:{fileinrepo} > {tempfilepath}")
|
||||
json1 = load_dict("临时文件/temp.json")
|
||||
os.system(f"git show {commitid2}:{fileinrepo} > {tempfilepath}")
|
||||
json2 = load_dict("临时文件/temp.json")
|
||||
os.remove("临时文件/temp.json")
|
||||
|
||||
diff_list = []
|
||||
new_or_deleted_list = [id for id in json1.keys() if not id in json2.keys()] + [id for id in json2.keys() if not id in json1.keys()]
|
||||
for id in [i for i in json1.keys() if i in json2.keys()]:
|
||||
current_diff = []
|
||||
for field in json1[id]:
|
||||
if not json1[id][field] == json2[id][field]:
|
||||
current_diff.append(field)
|
||||
if not current_diff == []:
|
||||
diff_list.append((id,current_diff.copy()))
|
||||
return (new_or_deleted_list,diff_list)
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("数据库工具, import用.")
|
||||
Reference in New Issue