Update 更新文档
This commit is contained in:
56
generate_continuous_code.py
Normal file
56
generate_continuous_code.py
Normal file
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
生成连续源代码文档 - 用于软件著作权申请
|
||||
功能:将清理后的源代码文件合并为一个连续文档,每个文件前加上文件路径注释
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
def main():
|
||||
# 配置路径
|
||||
source_dirs = [
|
||||
"QMainwindow",
|
||||
"Sqbase",
|
||||
"common_structures",
|
||||
"data_processing",
|
||||
"network_communication",
|
||||
"core"
|
||||
]
|
||||
|
||||
cleaned_code_dir = "cleaned_source_code"
|
||||
output_file = "软著申请材料/软件源代码文档.md"
|
||||
|
||||
# 确保输出目录存在
|
||||
os.makedirs(os.path.dirname(output_file), exist_ok=True)
|
||||
|
||||
with open(output_file, 'w', encoding='utf-8') as out:
|
||||
out.write("# 大单检测软件系统 源代码文档\n\n")
|
||||
out.write("## 说明\n")
|
||||
out.write("本文档包含软件著作权申请所需的源代码,已移除所有注释和空行。\n\n")
|
||||
out.write("## 源代码内容\n\n")
|
||||
|
||||
for source_dir in source_dirs:
|
||||
dir_path = os.path.join(cleaned_code_dir, source_dir)
|
||||
if not os.path.exists(dir_path):
|
||||
print(f"警告: 目录 {dir_path} 不存在")
|
||||
continue
|
||||
|
||||
for root, dirs, files in os.walk(dir_path):
|
||||
for file in files:
|
||||
if file.endswith(('.h', '.cpp')):
|
||||
file_path = os.path.join(root, file)
|
||||
|
||||
# 写入文件内容,不添加文件路径注释和行号
|
||||
try:
|
||||
with open(file_path, 'r', encoding='utf-8', errors='ignore') as f:
|
||||
content = f.read()
|
||||
# 移除文件末尾的空白行,然后写入内容
|
||||
out.write(content.rstrip())
|
||||
except Exception as e:
|
||||
print(f"读取文件 {file_path} 时出错: {e}")
|
||||
|
||||
print(f"连续源代码文档已生成: {output_file}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user