feat: 重构项目结构并添加平台同步基础架构
- 重构项目目录结构,将功能模块移至 modules/ 目录 - 创建平台同步基础架构,包括发布器基类和 GitHub 发布器 - 新增 UI 状态管理模块 (modules/ui/state.py) 统一管理会话状态 - 更新依赖配置,添加平台同步所需依赖 (httpx, pyperclip) - 整理文档结构,将所有文档分类移至 docs/ 目录 - 添加 .cursorrules 文件定义项目开发规范 - 清理根目录重复文件,保持项目结构整洁
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
"""
|
||||
清理根目录中的重复文档文件
|
||||
保留 docs/ 目录下的分类版本,删除根目录的重复文件
|
||||
"""
|
||||
from pathlib import Path
|
||||
|
||||
# 项目根目录
|
||||
root = Path(__file__).parent
|
||||
|
||||
# 需要保留在根目录的文档(不删除)
|
||||
keep_in_root = {
|
||||
"README.md",
|
||||
"DOCS.md", # 文档索引
|
||||
}
|
||||
|
||||
# 需要删除的文档文件(已在 docs/ 目录下)
|
||||
docs_to_remove = [
|
||||
# 功能文档
|
||||
"CONFIG_OPTIMIZER_FEATURE.md",
|
||||
"CONTENT_METRICS_FEATURE.md",
|
||||
"CONTENT_SCORER_FEATURE.md",
|
||||
"EEAT_FEATURE.md",
|
||||
"FACT_DENSITY_FEATURE.md",
|
||||
"JSON_LD_SCHEMA_FEATURE.md",
|
||||
"KEYWORD_MINING_FEATURE.md",
|
||||
"MULTIMODAL_FEATURE.md",
|
||||
"NEGATIVE_MONITOR_FEATURE.md",
|
||||
"OPTIMIZATION_TECHNIQUES_FEATURE.md",
|
||||
"RESOURCE_RECOMMENDER_FEATURE.md",
|
||||
"ROI_ANALYSIS_FEATURE.md",
|
||||
"SEMANTIC_EXPANSION_FEATURE.md",
|
||||
"TECHNICAL_CONFIG_FEATURE.md",
|
||||
"TOPIC_CLUSTER_FEATURE.md",
|
||||
"WORKFLOW_AUTOMATION_FEATURE.md",
|
||||
|
||||
# 分析报告
|
||||
"ANALYSIS_ACCURACY_REPORT.md",
|
||||
"CODE_DOCUMENTATION_ANALYSIS.md",
|
||||
"DOCUMENTATION_REVERSE_VERIFICATION.md",
|
||||
"FEATURE_ANALYSIS.md",
|
||||
"FEATURE_PRIORITY_ANALYSIS.md",
|
||||
"FUNCTION_VERIFICATION_REPORT.md",
|
||||
"GEO_COMPLIANCE_ANALYSIS.md",
|
||||
|
||||
# 指南文档
|
||||
"QUICK_START_GUIDE.md",
|
||||
"STORAGE_GUIDE.md",
|
||||
"PLATFORM_SETUP.md",
|
||||
"LAYOUT_UPGRADE_GUIDE.md",
|
||||
"DECISION_GUIDE.md",
|
||||
|
||||
# 实现文档
|
||||
"IMPLEMENTATION_SUMMARY.md",
|
||||
"PLATFORM_SYNC_ANALYSIS.md",
|
||||
"PLATFORM_SYNC_IMPLEMENTATION.md",
|
||||
"PLATFORM_SYNC_TEST.md",
|
||||
"INTEGRATION_NOTES.md",
|
||||
"FEATURES_COMPLETE_LIST.md",
|
||||
"ADVANCED_FEATURES.md",
|
||||
|
||||
# 重组相关文档(已移动到 docs/guides/)
|
||||
"DOCUMENTATION_CLEANUP_GUIDE.md",
|
||||
"PROJECT_STRUCTURE_ANALYSIS.md",
|
||||
"QUICK_REORGANIZE.md",
|
||||
"REORGANIZATION_SUMMARY.md",
|
||||
]
|
||||
|
||||
def cleanup_duplicates():
|
||||
"""清理根目录中的重复文档"""
|
||||
removed_count = 0
|
||||
skipped_count = 0
|
||||
|
||||
print("开始清理根目录中的重复文档...\n")
|
||||
|
||||
for doc_file in docs_to_remove:
|
||||
file_path = root / doc_file
|
||||
|
||||
if file_path.exists():
|
||||
# 检查是否在 docs/ 目录下存在
|
||||
found_in_docs = False
|
||||
for docs_subdir in ["features", "analysis", "guides", "implementation"]:
|
||||
docs_path = root / "docs" / docs_subdir / doc_file
|
||||
if docs_path.exists():
|
||||
found_in_docs = True
|
||||
break
|
||||
|
||||
if found_in_docs:
|
||||
try:
|
||||
file_path.unlink()
|
||||
print(f"✓ 已删除: {doc_file} (已在 docs/ 目录下)")
|
||||
removed_count += 1
|
||||
except Exception as e:
|
||||
print(f"✗ 删除失败: {doc_file} - {e}")
|
||||
else:
|
||||
print(f"⚠ 跳过: {doc_file} (docs/ 目录下未找到对应文件)")
|
||||
skipped_count += 1
|
||||
else:
|
||||
print(f"ℹ 不存在: {doc_file}")
|
||||
|
||||
print(f"\n✅ 清理完成!")
|
||||
print(f" - 已删除: {removed_count} 个文件")
|
||||
print(f" - 已跳过: {skipped_count} 个文件")
|
||||
print(f"\n📌 保留在根目录的文档:")
|
||||
for doc in sorted(keep_in_root):
|
||||
doc_path = root / doc
|
||||
if doc_path.exists():
|
||||
print(f" ✓ {doc}")
|
||||
else:
|
||||
print(f" ⚠ {doc} (不存在)")
|
||||
|
||||
if __name__ == "__main__":
|
||||
cleanup_duplicates()
|
||||
@@ -0,0 +1,91 @@
|
||||
"""
|
||||
清理根目录中的重复模块文件
|
||||
保留 modules/ 目录中的版本,删除根目录的重复文件
|
||||
"""
|
||||
from pathlib import Path
|
||||
|
||||
# 项目根目录
|
||||
root = Path(__file__).parent
|
||||
|
||||
# 需要保留在根目录的文件(不删除)
|
||||
keep_in_root = {
|
||||
"README.md",
|
||||
"DOCS.md",
|
||||
"requirements.txt",
|
||||
".gitignore",
|
||||
"geo_tool.py", # 主程序
|
||||
}
|
||||
|
||||
# 需要删除的重复模块文件(已在 modules/ 目录下)
|
||||
duplicate_modules = [
|
||||
"config_optimizer.py",
|
||||
"content_metrics.py",
|
||||
"content_scorer.py",
|
||||
"data_storage.py",
|
||||
"eeat_enhancer.py",
|
||||
"fact_density_enhancer.py",
|
||||
"keyword_mining.py",
|
||||
"keyword_tool.py",
|
||||
"multimodal_prompt.py",
|
||||
"negative_monitor.py",
|
||||
"optimization_techniques.py",
|
||||
"resource_recommender.py",
|
||||
"roi_analyzer.py",
|
||||
"schema_generator.py",
|
||||
"semantic_expander.py",
|
||||
"storage_example.py",
|
||||
"technical_config_generator.py",
|
||||
"topic_cluster.py",
|
||||
"workflow_automation.py",
|
||||
]
|
||||
|
||||
def cleanup_duplicates():
|
||||
"""清理根目录中的重复模块文件"""
|
||||
removed_count = 0
|
||||
skipped_count = 0
|
||||
error_count = 0
|
||||
|
||||
print("开始清理根目录中的重复模块文件...\n")
|
||||
print("⚠️ 警告:此操作将删除根目录的模块文件,请确保:")
|
||||
print(" 1. modules/ 目录中已有完整版本")
|
||||
print(" 2. geo_tool.py 中的导入路径已更新为 modules.xxx")
|
||||
print(" 3. 已测试程序可以正常运行\n")
|
||||
|
||||
for module_file in duplicate_modules:
|
||||
root_file = root / module_file
|
||||
modules_file = root / "modules" / module_file
|
||||
|
||||
if root_file.exists():
|
||||
# 检查 modules/ 目录下是否存在
|
||||
if modules_file.exists():
|
||||
try:
|
||||
root_file.unlink()
|
||||
print(f"✓ 已删除: {module_file} (modules/ 中已有)")
|
||||
removed_count += 1
|
||||
except Exception as e:
|
||||
print(f"✗ 删除失败: {module_file} - {e}")
|
||||
error_count += 1
|
||||
else:
|
||||
print(f"⚠ 跳过: {module_file} (modules/ 中不存在,保留根目录版本)")
|
||||
skipped_count += 1
|
||||
else:
|
||||
print(f"ℹ 不存在: {module_file}")
|
||||
|
||||
print(f"\n✅ 清理完成!")
|
||||
print(f" - 已删除: {removed_count} 个文件")
|
||||
print(f" - 已跳过: {skipped_count} 个文件")
|
||||
print(f" - 错误: {error_count} 个文件")
|
||||
|
||||
if removed_count > 0:
|
||||
print(f"\n📌 重要提醒:")
|
||||
print(f" 1. 请运行 'streamlit run geo_tool.py' 测试程序")
|
||||
print(f" 2. 确认所有功能正常工作")
|
||||
print(f" 3. 如有问题,可从 Git 历史恢复文件")
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
response = input("\n确认要删除根目录的重复模块文件吗?(yes/no): ")
|
||||
if response.lower() in ['yes', 'y']:
|
||||
cleanup_duplicates()
|
||||
else:
|
||||
print("操作已取消")
|
||||
@@ -0,0 +1,50 @@
|
||||
"""
|
||||
移动重组相关文档到 docs/guides/ 目录
|
||||
"""
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
|
||||
# 项目根目录
|
||||
root = Path(__file__).parent
|
||||
|
||||
# 需要移动的重组相关文档
|
||||
reorganization_docs = [
|
||||
"DOCUMENTATION_CLEANUP_GUIDE.md",
|
||||
"PROJECT_STRUCTURE_ANALYSIS.md",
|
||||
"QUICK_REORGANIZE.md",
|
||||
"REORGANIZATION_SUMMARY.md",
|
||||
]
|
||||
|
||||
# 目标目录
|
||||
target_dir = root / "docs" / "guides"
|
||||
target_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
def move_reorganization_docs():
|
||||
"""移动重组相关文档到 docs/guides/"""
|
||||
moved_count = 0
|
||||
|
||||
print("开始移动重组相关文档到 docs/guides/...\n")
|
||||
|
||||
for doc_file in reorganization_docs:
|
||||
src = root / doc_file
|
||||
dest = target_dir / doc_file
|
||||
|
||||
if src.exists():
|
||||
if dest.exists():
|
||||
print(f"⚠ 跳过: {doc_file} (目标位置已存在)")
|
||||
else:
|
||||
try:
|
||||
shutil.move(str(src), str(dest))
|
||||
print(f"✓ 已移动: {doc_file} -> docs/guides/")
|
||||
moved_count += 1
|
||||
except Exception as e:
|
||||
print(f"✗ 移动失败: {doc_file} - {e}")
|
||||
else:
|
||||
print(f"ℹ 不存在: {doc_file}")
|
||||
|
||||
print(f"\n✅ 移动完成!")
|
||||
print(f" - 已移动: {moved_count} 个文件")
|
||||
print(f"\n📌 这些文档现在位于: docs/guides/")
|
||||
|
||||
if __name__ == "__main__":
|
||||
move_reorganization_docs()
|
||||
@@ -0,0 +1,52 @@
|
||||
"""
|
||||
移动工具脚本到 scripts/ 目录
|
||||
"""
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
|
||||
# 项目根目录
|
||||
root = Path(__file__).parent
|
||||
|
||||
# 需要移动的工具脚本
|
||||
scripts_to_move = [
|
||||
"cleanup_duplicate_docs.py",
|
||||
"move_reorganization_docs.py",
|
||||
"reorganize_files.py",
|
||||
"update_imports.py",
|
||||
"update_doc_references.py",
|
||||
]
|
||||
|
||||
# 目标目录
|
||||
target_dir = root / "scripts"
|
||||
target_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
def move_scripts():
|
||||
"""移动工具脚本到 scripts/ 目录"""
|
||||
moved_count = 0
|
||||
|
||||
print("开始移动工具脚本到 scripts/ 目录...\n")
|
||||
|
||||
for script_file in scripts_to_move:
|
||||
src = root / script_file
|
||||
dest = target_dir / script_file
|
||||
|
||||
if src.exists():
|
||||
if dest.exists():
|
||||
print(f"⚠ 跳过: {script_file} (目标位置已存在)")
|
||||
else:
|
||||
try:
|
||||
shutil.move(str(src), str(dest))
|
||||
print(f"✓ 已移动: {script_file} -> scripts/")
|
||||
moved_count += 1
|
||||
except Exception as e:
|
||||
print(f"✗ 移动失败: {script_file} - {e}")
|
||||
else:
|
||||
print(f"ℹ 不存在: {script_file}")
|
||||
|
||||
print(f"\n✅ 移动完成!")
|
||||
print(f" - 已移动: {moved_count} 个文件")
|
||||
print(f"\n📌 这些脚本现在位于: scripts/")
|
||||
print(f" 使用方式: python scripts/script_name.py")
|
||||
|
||||
if __name__ == "__main__":
|
||||
move_scripts()
|
||||
@@ -0,0 +1,136 @@
|
||||
"""
|
||||
临时脚本:重组项目文件结构
|
||||
"""
|
||||
import os
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
# 项目根目录
|
||||
root = Path(__file__).parent
|
||||
|
||||
# 文档分类映射
|
||||
doc_mapping = {
|
||||
# 功能文档
|
||||
"features": [
|
||||
"*_FEATURE.md"
|
||||
],
|
||||
# 分析报告
|
||||
"analysis": [
|
||||
"ANALYSIS_ACCURACY_REPORT.md",
|
||||
"CODE_DOCUMENTATION_ANALYSIS.md",
|
||||
"DOCUMENTATION_REVERSE_VERIFICATION.md",
|
||||
"FEATURE_ANALYSIS.md",
|
||||
"FEATURE_PRIORITY_ANALYSIS.md",
|
||||
"FUNCTION_VERIFICATION_REPORT.md",
|
||||
"GEO_COMPLIANCE_ANALYSIS.md",
|
||||
],
|
||||
# 指南文档
|
||||
"guides": [
|
||||
"QUICK_START_GUIDE.md",
|
||||
"STORAGE_GUIDE.md",
|
||||
"PLATFORM_SETUP.md",
|
||||
"LAYOUT_UPGRADE_GUIDE.md",
|
||||
"DECISION_GUIDE.md",
|
||||
],
|
||||
# 实现文档
|
||||
"implementation": [
|
||||
"IMPLEMENTATION_SUMMARY.md",
|
||||
"PLATFORM_SYNC_ANALYSIS.md",
|
||||
"PLATFORM_SYNC_IMPLEMENTATION.md",
|
||||
"PLATFORM_SYNC_TEST.md",
|
||||
"INTEGRATION_NOTES.md",
|
||||
"FEATURES_COMPLETE_LIST.md",
|
||||
"ADVANCED_FEATURES.md",
|
||||
],
|
||||
}
|
||||
|
||||
# 功能模块文件列表
|
||||
module_files = [
|
||||
"data_storage.py",
|
||||
"keyword_tool.py",
|
||||
"content_scorer.py",
|
||||
"eeat_enhancer.py",
|
||||
"semantic_expander.py",
|
||||
"fact_density_enhancer.py",
|
||||
"schema_generator.py",
|
||||
"topic_cluster.py",
|
||||
"multimodal_prompt.py",
|
||||
"roi_analyzer.py",
|
||||
"workflow_automation.py",
|
||||
"keyword_mining.py",
|
||||
"optimization_techniques.py",
|
||||
"content_metrics.py",
|
||||
"technical_config_generator.py",
|
||||
"negative_monitor.py",
|
||||
"resource_recommender.py",
|
||||
"config_optimizer.py",
|
||||
"storage_example.py",
|
||||
]
|
||||
|
||||
def move_files():
|
||||
"""移动文件到对应目录"""
|
||||
moved_count = 0
|
||||
|
||||
# 移动功能文档(*_FEATURE.md)
|
||||
features_dir = root / "docs" / "features"
|
||||
features_dir.mkdir(parents=True, exist_ok=True)
|
||||
for file in root.glob("*_FEATURE.md"):
|
||||
try:
|
||||
dest = features_dir / file.name
|
||||
if not dest.exists():
|
||||
shutil.move(str(file), str(dest))
|
||||
print(f"✓ Moved {file.name} -> docs/features/")
|
||||
moved_count += 1
|
||||
else:
|
||||
print(f"⚠ Skipped {file.name} (already exists)")
|
||||
except Exception as e:
|
||||
print(f"✗ Failed to move {file.name}: {e}")
|
||||
|
||||
# 移动其他文档
|
||||
for category, files in doc_mapping.items():
|
||||
if category == "features":
|
||||
continue # 已经处理过了
|
||||
|
||||
target_dir = root / "docs" / category
|
||||
target_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
for filename in files:
|
||||
src = root / filename
|
||||
if src.exists():
|
||||
try:
|
||||
dest = target_dir / filename
|
||||
if not dest.exists():
|
||||
shutil.move(str(src), str(dest))
|
||||
print(f"✓ Moved {filename} -> docs/{category}/")
|
||||
moved_count += 1
|
||||
else:
|
||||
print(f"⚠ Skipped {filename} (already exists)")
|
||||
except Exception as e:
|
||||
print(f"✗ Failed to move {filename}: {e}")
|
||||
else:
|
||||
print(f"⚠ File not found: {filename}")
|
||||
|
||||
# 移动功能模块
|
||||
modules_dir = root / "modules"
|
||||
modules_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
for filename in module_files:
|
||||
src = root / filename
|
||||
if src.exists():
|
||||
try:
|
||||
dest = modules_dir / filename
|
||||
if not dest.exists():
|
||||
shutil.move(str(src), str(dest))
|
||||
print(f"✓ Moved {filename} -> modules/")
|
||||
moved_count += 1
|
||||
else:
|
||||
print(f"⚠ Skipped {filename} (already exists)")
|
||||
except Exception as e:
|
||||
print(f"✗ Failed to move {filename}: {e}")
|
||||
else:
|
||||
print(f"⚠ File not found: {filename}")
|
||||
|
||||
print(f"\n✅ Total moved: {moved_count} files")
|
||||
|
||||
if __name__ == "__main__":
|
||||
move_files()
|
||||
@@ -0,0 +1,124 @@
|
||||
"""
|
||||
更新所有文档文件中的路径引用
|
||||
"""
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
# 项目根目录
|
||||
root = Path(__file__).parent
|
||||
|
||||
# 文档路径映射(旧路径 -> 新路径)
|
||||
doc_path_mappings = {
|
||||
# 功能文档
|
||||
r'`([A-Z_]+_FEATURE\.md)`': r'`docs/features/\1`',
|
||||
r'\(([A-Z_]+_FEATURE\.md)\)': r'(docs/features/\1)',
|
||||
r'([A-Z_]+_FEATURE\.md)': r'docs/features/\1',
|
||||
|
||||
# 分析报告
|
||||
r'`(ANALYSIS_ACCURACY_REPORT\.md)`': r'`docs/analysis/\1`',
|
||||
r'`(CODE_DOCUMENTATION_ANALYSIS\.md)`': r'`docs/analysis/\1`',
|
||||
r'`(DOCUMENTATION_REVERSE_VERIFICATION\.md)`': r'`docs/analysis/\1`',
|
||||
r'`(FEATURE_ANALYSIS\.md)`': r'`docs/analysis/\1`',
|
||||
r'`(FEATURE_PRIORITY_ANALYSIS\.md)`': r'`docs/analysis/\1`',
|
||||
r'`(FUNCTION_VERIFICATION_REPORT\.md)`': r'`docs/analysis/\1`',
|
||||
r'`(GEO_COMPLIANCE_ANALYSIS\.md)`': r'`docs/analysis/\1`',
|
||||
|
||||
# 指南文档
|
||||
r'`(QUICK_START_GUIDE\.md)`': r'`docs/guides/\1`',
|
||||
r'`(STORAGE_GUIDE\.md)`': r'`docs/guides/\1`',
|
||||
r'`(PLATFORM_SETUP\.md)`': r'`docs/guides/\1`',
|
||||
r'`(LAYOUT_UPGRADE_GUIDE\.md)`': r'`docs/guides/\1`',
|
||||
r'`(DECISION_GUIDE\.md)`': r'`docs/guides/\1`',
|
||||
|
||||
# 实现文档
|
||||
r'`(IMPLEMENTATION_SUMMARY\.md)`': r'`docs/implementation/\1`',
|
||||
r'`(PLATFORM_SYNC_ANALYSIS\.md)`': r'`docs/implementation/\1`',
|
||||
r'`(PLATFORM_SYNC_IMPLEMENTATION\.md)`': r'`docs/implementation/\1`',
|
||||
r'`(PLATFORM_SYNC_TEST\.md)`': r'`docs/implementation/\1`',
|
||||
r'`(INTEGRATION_NOTES\.md)`': r'`docs/implementation/\1`',
|
||||
r'`(FEATURES_COMPLETE_LIST\.md)`': r'`docs/implementation/\1`',
|
||||
r'`(ADVANCED_FEATURES\.md)`': r'`docs/implementation/\1`',
|
||||
|
||||
# 模块文件路径
|
||||
r'`([a-z_]+\.py)`': r'`modules/\1`',
|
||||
r'\(([a-z_]+\.py)\)': r'(modules/\1)',
|
||||
}
|
||||
|
||||
# 需要更新的模块文件名
|
||||
module_files = [
|
||||
"data_storage.py",
|
||||
"keyword_tool.py",
|
||||
"content_scorer.py",
|
||||
"eeat_enhancer.py",
|
||||
"semantic_expander.py",
|
||||
"fact_density_enhancer.py",
|
||||
"schema_generator.py",
|
||||
"topic_cluster.py",
|
||||
"multimodal_prompt.py",
|
||||
"roi_analyzer.py",
|
||||
"workflow_automation.py",
|
||||
"keyword_mining.py",
|
||||
"optimization_techniques.py",
|
||||
"content_metrics.py",
|
||||
"technical_config_generator.py",
|
||||
"negative_monitor.py",
|
||||
"resource_recommender.py",
|
||||
"config_optimizer.py",
|
||||
]
|
||||
|
||||
def update_doc_references(file_path: Path):
|
||||
"""更新单个文档文件中的路径引用"""
|
||||
try:
|
||||
content = file_path.read_text(encoding='utf-8')
|
||||
original_content = content
|
||||
updated = False
|
||||
|
||||
# 更新文档路径引用
|
||||
for pattern, replacement in doc_path_mappings.items():
|
||||
if re.search(pattern, content):
|
||||
content = re.sub(pattern, replacement, content)
|
||||
updated = True
|
||||
|
||||
# 更新模块文件路径(更精确的匹配)
|
||||
for module_file in module_files:
|
||||
# 匹配 `module_file` 或 (module_file) 格式
|
||||
patterns = [
|
||||
(rf'`{re.escape(module_file)}`', f'`modules/{module_file}`'),
|
||||
(rf'\({re.escape(module_file)}\)', f'(modules/{module_file})'),
|
||||
(rf'([^/]){re.escape(module_file)}', rf'\1modules/{module_file}'),
|
||||
]
|
||||
for pattern, replacement in patterns:
|
||||
if re.search(pattern, content):
|
||||
content = re.sub(pattern, replacement, content)
|
||||
updated = True
|
||||
|
||||
if updated and content != original_content:
|
||||
file_path.write_text(content, encoding='utf-8')
|
||||
print(f"✓ Updated: {file_path.relative_to(root)}")
|
||||
return True
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"✗ Error updating {file_path.name}: {e}")
|
||||
return False
|
||||
|
||||
def main():
|
||||
"""更新所有文档文件中的路径引用"""
|
||||
updated_count = 0
|
||||
|
||||
# 更新README.md
|
||||
readme = root / "README.md"
|
||||
if readme.exists():
|
||||
if update_doc_references(readme):
|
||||
updated_count += 1
|
||||
|
||||
# 更新docs目录下的所有.md文件
|
||||
docs_dir = root / "docs"
|
||||
if docs_dir.exists():
|
||||
for md_file in docs_dir.rglob("*.md"):
|
||||
if update_doc_references(md_file):
|
||||
updated_count += 1
|
||||
|
||||
print(f"\n✅ Updated {updated_count} documentation files")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,99 @@
|
||||
"""
|
||||
更新所有Python文件中的导入路径
|
||||
"""
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
# 项目根目录
|
||||
root = Path(__file__).parent
|
||||
|
||||
# 需要更新的导入映射
|
||||
import_mappings = {
|
||||
"from data_storage": "from modules.data_storage",
|
||||
"from keyword_tool": "from modules.keyword_tool",
|
||||
"from content_scorer": "from modules.content_scorer",
|
||||
"from eeat_enhancer": "from modules.eeat_enhancer",
|
||||
"from semantic_expander": "from modules.semantic_expander",
|
||||
"from fact_density_enhancer": "from modules.fact_density_enhancer",
|
||||
"from schema_generator": "from modules.schema_generator",
|
||||
"from topic_cluster": "from modules.topic_cluster",
|
||||
"from multimodal_prompt": "from modules.multimodal_prompt",
|
||||
"from roi_analyzer": "from modules.roi_analyzer",
|
||||
"from workflow_automation": "from modules.workflow_automation",
|
||||
"from keyword_mining": "from modules.keyword_mining",
|
||||
"from optimization_techniques": "from modules.optimization_techniques",
|
||||
"from content_metrics": "from modules.content_metrics",
|
||||
"from technical_config_generator": "from modules.technical_config_generator",
|
||||
"from negative_monitor": "from modules.negative_monitor",
|
||||
"from resource_recommender": "from modules.resource_recommender",
|
||||
"from config_optimizer": "from modules.config_optimizer",
|
||||
"import data_storage": "import modules.data_storage",
|
||||
"import keyword_tool": "import modules.keyword_tool",
|
||||
"import content_scorer": "import modules.content_scorer",
|
||||
"import eeat_enhancer": "import modules.eeat_enhancer",
|
||||
"import semantic_expander": "import modules.semantic_expander",
|
||||
"import fact_density_enhancer": "import modules.fact_density_enhancer",
|
||||
"import schema_generator": "import modules.schema_generator",
|
||||
"import topic_cluster": "import modules.topic_cluster",
|
||||
"import multimodal_prompt": "import modules.multimodal_prompt",
|
||||
"import roi_analyzer": "import modules.roi_analyzer",
|
||||
"import workflow_automation": "import modules.workflow_automation",
|
||||
"import keyword_mining": "import modules.keyword_mining",
|
||||
"import optimization_techniques": "import modules.optimization_techniques",
|
||||
"import content_metrics": "import modules.content_metrics",
|
||||
"import technical_config_generator": "import modules.technical_config_generator",
|
||||
"import negative_monitor": "import modules.negative_monitor",
|
||||
"import resource_recommender": "import modules.resource_recommender",
|
||||
"import config_optimizer": "import modules.config_optimizer",
|
||||
}
|
||||
|
||||
def update_file_imports(file_path: Path):
|
||||
"""更新单个文件中的导入路径"""
|
||||
try:
|
||||
content = file_path.read_text(encoding='utf-8')
|
||||
original_content = content
|
||||
updated = False
|
||||
|
||||
for old_import, new_import in import_mappings.items():
|
||||
# 使用正则表达式匹配完整的导入语句
|
||||
pattern = rf'({re.escape(old_import)})(\s+import|\s+as|\s+)'
|
||||
if re.search(pattern, content):
|
||||
content = re.sub(pattern, rf'{new_import}\2', content)
|
||||
updated = True
|
||||
|
||||
if updated:
|
||||
file_path.write_text(content, encoding='utf-8')
|
||||
print(f"✓ Updated: {file_path.name}")
|
||||
return True
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"✗ Error updating {file_path.name}: {e}")
|
||||
return False
|
||||
|
||||
def main():
|
||||
"""更新所有Python文件中的导入路径"""
|
||||
# 需要更新的文件列表
|
||||
files_to_update = [
|
||||
root / "geo_tool.py",
|
||||
root / "modules" / "storage_example.py",
|
||||
]
|
||||
|
||||
# 如果modules目录存在,也检查其中的文件
|
||||
modules_dir = root / "modules"
|
||||
if modules_dir.exists():
|
||||
for py_file in modules_dir.glob("*.py"):
|
||||
if py_file.name != "__init__.py":
|
||||
files_to_update.append(py_file)
|
||||
|
||||
updated_count = 0
|
||||
for file_path in files_to_update:
|
||||
if file_path.exists():
|
||||
if update_file_imports(file_path):
|
||||
updated_count += 1
|
||||
else:
|
||||
print(f"⚠ File not found: {file_path}")
|
||||
|
||||
print(f"\n✅ Updated {updated_count} files")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,92 @@
|
||||
"""
|
||||
更新文档中对工具脚本的引用路径
|
||||
将旧路径更新为 scripts/ 前缀
|
||||
"""
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
# 项目根目录
|
||||
root = Path(__file__).parent
|
||||
|
||||
# 工具脚本列表
|
||||
scripts = [
|
||||
"cleanup_duplicate_docs.py",
|
||||
"move_reorganization_docs.py",
|
||||
"reorganize_files.py",
|
||||
"update_imports.py",
|
||||
"update_doc_references.py",
|
||||
]
|
||||
|
||||
# 路径更新映射
|
||||
path_mappings = {
|
||||
# 旧路径 -> 新路径
|
||||
r'`(cleanup_duplicate_docs\.py)`': r'`scripts/\1`',
|
||||
r'`(move_reorganization_docs\.py)`': r'`scripts/\1`',
|
||||
r'`(reorganize_files\.py)`': r'`scripts/\1`',
|
||||
r'`(update_imports\.py)`': r'`scripts/\1`',
|
||||
r'`(update_doc_references\.py)`': r'`scripts/\1`',
|
||||
|
||||
# 命令中的路径
|
||||
r'python (cleanup_duplicate_docs\.py)': r'python scripts/\1',
|
||||
r'python (move_reorganization_docs\.py)': r'python scripts/\1',
|
||||
r'python (reorganize_files\.py)': r'python scripts/\1',
|
||||
r'python (update_imports\.py)': r'python scripts/\1',
|
||||
r'python (update_doc_references\.py)': r'python scripts/\1',
|
||||
|
||||
# 文档中的描述
|
||||
r'- `(cleanup_duplicate_docs\.py)`': r'- `scripts/\1`',
|
||||
r'- `(move_reorganization_docs\.py)`': r'- `scripts/\1`',
|
||||
r'- `(reorganize_files\.py)`': r'- `scripts/\1`',
|
||||
r'- `(update_imports\.py)`': r'- `scripts/\1`',
|
||||
r'- `(update_doc_references\.py)`': r'- `scripts/\1`',
|
||||
}
|
||||
|
||||
def update_script_references(file_path: Path):
|
||||
"""更新单个文件中的脚本引用路径"""
|
||||
try:
|
||||
content = file_path.read_text(encoding='utf-8')
|
||||
original_content = content
|
||||
updated = False
|
||||
|
||||
# 更新脚本路径引用
|
||||
for pattern, replacement in path_mappings.items():
|
||||
if re.search(pattern, content):
|
||||
content = re.sub(pattern, replacement, content)
|
||||
updated = True
|
||||
|
||||
if updated and content != original_content:
|
||||
file_path.write_text(content, encoding='utf-8')
|
||||
print(f"✓ Updated: {file_path.relative_to(root)}")
|
||||
return True
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"✗ Error updating {file_path.name}: {e}")
|
||||
return False
|
||||
|
||||
def main():
|
||||
"""更新所有文档中的脚本引用路径"""
|
||||
updated_count = 0
|
||||
|
||||
# 更新根目录的文档
|
||||
root_docs = [
|
||||
"FINAL_OPTIMIZATION_GUIDE.md",
|
||||
"ADVANCED_OPTIMIZATION_PLAN.md",
|
||||
]
|
||||
|
||||
for doc_file in root_docs:
|
||||
doc_path = root / doc_file
|
||||
if doc_path.exists():
|
||||
if update_script_references(doc_path):
|
||||
updated_count += 1
|
||||
|
||||
# 更新 docs/ 目录下的所有 .md 文件
|
||||
docs_dir = root / "docs"
|
||||
if docs_dir.exists():
|
||||
for md_file in docs_dir.rglob("*.md"):
|
||||
if update_script_references(md_file):
|
||||
updated_count += 1
|
||||
|
||||
print(f"\n✅ Updated {updated_count} documentation files")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user