60 lines
2.3 KiB
Python
60 lines
2.3 KiB
Python
|
|
# -*- coding: utf-8 -*-
|
||
|
|
import os, hashlib, json, collections
|
||
|
|
ROOT = r"D:\资料\03-项目开发\wecom_it_smart_desk\docs"
|
||
|
|
OLD = ["01-产品设计","02-产品需求","03-技术架构","04-原型设计","06-测试质量","08-安全审计","09-部署运维","10-项目管理","11-历史归档"]
|
||
|
|
NEW = ["01-产品文档","02-技术文档","03-测试文档","04-运维文档","05-运营文档","06-安全审计","07-项目管理","08-历史归档"]
|
||
|
|
OLD_ROOT_FILES = ["class-diagram.mermaid","sequence-diagram.mermaid","system_design.md"]
|
||
|
|
|
||
|
|
def h(p):
|
||
|
|
try:
|
||
|
|
return hashlib.md5(open(p,'rb').read()).hexdigest()
|
||
|
|
except Exception as e:
|
||
|
|
return "ERR:"+str(e)
|
||
|
|
|
||
|
|
newidx = collections.defaultdict(list)
|
||
|
|
newcount = 0
|
||
|
|
for d in NEW:
|
||
|
|
base = os.path.join(ROOT, d)
|
||
|
|
if not os.path.isdir(base): continue
|
||
|
|
for dp, dn, fn in os.walk(base):
|
||
|
|
for f in fn:
|
||
|
|
fp = os.path.join(dp, f)
|
||
|
|
newidx[f].append((os.path.relpath(fp, ROOT), h(fp)))
|
||
|
|
newcount += 1
|
||
|
|
|
||
|
|
res = {"dup_same":[], "dup_diff":[], "unique":[]}
|
||
|
|
oldcount = 0
|
||
|
|
for d in OLD + OLD_ROOT_FILES:
|
||
|
|
base = os.path.join(ROOT, d)
|
||
|
|
files = []
|
||
|
|
if os.path.isdir(base):
|
||
|
|
for dp, dn, fn in os.walk(base):
|
||
|
|
for f in fn:
|
||
|
|
files.append(os.path.join(dp,f))
|
||
|
|
elif os.path.isfile(base):
|
||
|
|
files.append(base)
|
||
|
|
for fp in files:
|
||
|
|
oldcount += 1
|
||
|
|
rel = os.path.relpath(fp, ROOT)
|
||
|
|
bn = os.path.basename(fp)
|
||
|
|
oh = h(fp)
|
||
|
|
cands = newidx.get(bn, [])
|
||
|
|
if not cands:
|
||
|
|
res["unique"].append((rel, None))
|
||
|
|
elif any(c[1]==oh for c in cands):
|
||
|
|
res["dup_same"].append((rel, [c[0] for c in cands if c[1]==oh][0]))
|
||
|
|
else:
|
||
|
|
res["dup_diff"].append((rel, [c[0] for c in cands]))
|
||
|
|
|
||
|
|
print("新结构文件数:", newcount, "| 旧结构(含根散件)文件数:", oldcount)
|
||
|
|
print("完全重复(同名同内容):", len(res["dup_same"]))
|
||
|
|
print("同名但内容不同 :", len(res["dup_diff"]))
|
||
|
|
print("新结构中不存在(唯一):", len(res["unique"]))
|
||
|
|
print("\n===== 同名内容不同 =====")
|
||
|
|
for a,b in res["dup_diff"]:
|
||
|
|
print(" -", a, " <-> ", b)
|
||
|
|
print("\n===== 唯一(新结构缺失) =====")
|
||
|
|
for a,_ in res["unique"]:
|
||
|
|
print(" -", a)
|
||
|
|
json.dump(res, open(r"D:\资料\03-项目开发\wecom_it_smart_desk\docs_cmp_result.json","w",encoding="utf-8"), ensure_ascii=False, indent=1)
|