46 lines
1.9 KiB
Python
46 lines
1.9 KiB
Python
import os
|
|
|
|
OUTPUT_SNAPSHOT = "project_code_snapshot.md"
|
|
|
|
# Расширения файлов для включения в снимок (только исходный код)
|
|
ALLOWED_EXTENSIONS = {'.py', '.json', '.sh', '.ini', '.js', '.html', '.css', '.sql'}
|
|
|
|
# Исключаемые каталоги (убираем docs, кэши, архивы и окружения)
|
|
EXCLUDE_DIRS = {
|
|
'.git', '__pycache__', 'venv', '.venv', 'output', 'logs',
|
|
'extracted_project', 'docs', 'data'
|
|
}
|
|
|
|
# Исключаемые файлы
|
|
EXCLUDE_FILES = {
|
|
OUTPUT_SNAPSHOT,
|
|
'api_code_snapshot.md',
|
|
'project_code_snapshot.md',
|
|
'scud_orion_ai_v2.tar.gz',
|
|
'scud_context_api.tar.gz',
|
|
'context_memory.db'
|
|
}
|
|
|
|
print(f"🔄 Сборка оптимизированного слепка кода в {OUTPUT_SNAPSHOT}...")
|
|
|
|
with open(OUTPUT_SNAPSHOT, 'w', encoding='utf-8') as out:
|
|
out.write("# 📦 ОПТИМИЗИРОВАННЫЙ СЛЕПОК ИСХОДНОГО КОДА scud_orion_ai\n\n")
|
|
|
|
for root, dirs, files in os.walk('.'):
|
|
dirs[:] = [d for d in dirs if d not in EXCLUDE_DIRS]
|
|
|
|
for file in sorted(files):
|
|
ext = os.path.splitext(file)[1].lower()
|
|
if ext in ALLOWED_EXTENSIONS and file not in EXCLUDE_FILES:
|
|
filepath = os.path.join(root, file)
|
|
out.write(f"## File: `{filepath}`\n")
|
|
out.write("```" + ext.replace('.', '') + "\n")
|
|
try:
|
|
with open(filepath, 'r', encoding='utf-8', errors='replace') as f:
|
|
out.write(f.read())
|
|
except Exception as e:
|
|
out.write(f"// Ошибка чтения файла: {e}\n")
|
|
out.write("\n```\n\n")
|
|
|
|
size_kb = os.path.getsize(OUTPUT_SNAPSHOT) / 1024
|
|
print(f"✓ Слепок успешно создан: {OUTPUT_SNAPSHOT} ({size_kb:.1f} KB)") |