etms/remove_org_refs.py
liyuchen d9fba9a316 Remove organization references (de-identify)
- Replace CETC54 references with ETMS
- Replace com.cetc54 package with com.example
- Rename cetc54 directories to etms
- Replace CECT54.WebUI to ETMS.WebUI
- Replace organization names (中国电科54所 -> XX公司)
- Replace internal system URLs (cetc54.com -> example.com)
2026-04-16 17:14:56 +08:00

112 lines
2.7 KiB
Python

#!/usr/bin/env python3
"""
移除所有与XX公司相关的标识信息
"""
import os
import re
# 项目根目录
PROJECT_ROOT = r"d:/lyc/etms/jcdp/jcdp"
# 替换规则:(原字符串, 替换为)
REPLACEMENTS = [
# 组织名称
("XX公司", "XX公司"),
("XX集团", "XX集团"),
("XX研究所", "XX研究所"),
("XX所", "XX所"),
("etms", "etms"),
("ETMS", "ETMS"),
# 包名
("com.etms", "com.example"),
# URL 引用
("etms.com", "example.com"),
("isms.etms.com", "isms.example.com"),
("pdmlogin.etms.com", "pdmlogin.example.com"),
("pdm.etms.com", "pdm.example.com"),
("bbs.etms.com", "bbs.example.com"),
("xxjh.etms.com", "xxjh.example.com"),
# 内部系统标识
("ETMS_", "ETMS_"),
]
def should_skip_file(filepath):
"""检查是否应该跳过文件"""
skip_patterns = [
'.git/',
'.workbuddy/',
'.codebuddy/',
'.class',
'.jar',
'.png',
'.jpg',
'.jpeg',
'.gif',
'.ico',
'.flv',
'.swf',
'.otf',
'.ttf',
'.woff',
'.woff2',
]
for pattern in skip_patterns:
if pattern in filepath:
return True
return False
def process_file(filepath):
"""处理单个文件"""
if should_skip_file(filepath):
return 0
try:
with open(filepath, 'r', encoding='utf-8', errors='ignore') as f:
content = f.read()
except Exception as e:
print(f" 跳过(读取错误): {filepath}")
return 0
original = content
for old, new in REPLACEMENTS:
content = content.replace(old, new)
if content != original:
try:
with open(filepath, 'w', encoding='utf-8') as f:
f.write(content)
return 1
except Exception as e:
print(f" 跳过(写入错误): {filepath}")
return 0
return 0
def main():
modified_count = 0
file_count = 0
print("开始处理文件...")
print(f"替换规则:")
for old, new in REPLACEMENTS:
print(f" {old} -> {new}")
print()
for root, dirs, files in os.walk(PROJECT_ROOT):
# 跳过 .git 目录
dirs[:] = [d for d in dirs if d not in ['.git', '.workbuddy', '.codebuddy']]
for filename in files:
filepath = os.path.join(root, filename)
file_count += 1
if process_file(filepath):
print(f"已修改: {os.path.relpath(filepath, PROJECT_ROOT)}")
modified_count += 1
print(f"\n处理完成!")
print(f"总文件数: {file_count}")
print(f"修改文件数: {modified_count}")
if __name__ == "__main__":
main()