pyside_queue_sqlite/scripts/code_content.py

39 lines
1.6 KiB
Python
Raw Permalink Normal View History

2025-09-06 16:06:30 +08:00
import os
import sys
2025-09-13 12:13:52 +08:00
2025-09-06 16:06:30 +08:00
def generate_markdown_from_py_files(directory, output_file):
2025-09-13 12:13:52 +08:00
with open(output_file, "w", encoding="utf-8") as md_file:
2025-09-06 16:06:30 +08:00
for root, dirs, files in os.walk(directory):
# 排除 venv 目录
2025-09-13 12:13:52 +08:00
dirs[:] = [d for d in dirs if d != ".venv"]
dirs[:] = [d for d in dirs if d != ".vscode"]
dirs[:] = [d for d in dirs if d != "scripts"]
dirs[:] = [d for d in dirs if d != "build"]
dirs[:] = [d for d in dirs if d != "lib"]
dirs[:] = [d for d in dirs if d != "dist"]
dirs[:] = [d for d in dirs if d != "node_modules"]
dirs[:] = [d for d in dirs if d != "plugins"]
2025-09-06 16:06:30 +08:00
for file in files:
2025-09-13 12:13:52 +08:00
if (
file.endswith(".py")
or file.endswith(".rs")
or file.endswith(".js")
or file.endswith(".vue")
):
2025-09-06 16:06:30 +08:00
file_path = os.path.join(root, file)
2025-09-13 12:13:52 +08:00
md_file.write(f"`{file_path}`\n")
md_file.write("```python\n")
with open(file_path, "r", encoding="utf-8") as py_file:
2025-09-06 16:06:30 +08:00
md_file.write(py_file.read())
2025-09-13 12:13:52 +08:00
md_file.write("\n```\n\n")
2025-09-06 16:06:30 +08:00
if __name__ == "__main__":
# 指定目录和输出文件名
2025-09-13 12:13:52 +08:00
target_directory = sys.argv[1] # 替换为你的目标目录
output_markdown_file = "output.md" # 输出的 Markdown 文件名
2025-09-06 16:06:30 +08:00
generate_markdown_from_py_files(target_directory, output_markdown_file)
2025-09-13 12:13:52 +08:00
print(f"Markdown 文件已生成:{output_markdown_file}")