-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_structure.py
58 lines (44 loc) · 1.71 KB
/
export_structure.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import os
import json
def should_exclude(path):
exclude_dirs = {'.venv', 'venv', '__pycache__', 'node_modules', '.git',
'audio_uploads', '.idea', '.DS_Store'}
exclude_extensions = {'.pyc', '.pyo', '.pyd', '.db', '.sqlite3', '.wav', '.pdf',
'.png', '.jpg', '.jpeg', '.json', '.DS_Store', '.sqlite'}
parts = path.split(os.sep)
#print(parts)
if any(part in exclude_dirs for part in parts):
return True
_, ext = os.path.splitext(path)
#print(ext)
return ext.lower() in exclude_extensions
def read_file_content(file_path):
try:
with open(file_path, 'r', encoding='utf-8') as file:
return file.read()
except Exception as e:
return f"Error reading file: {str(e)}"
def explore_directory(directory):
structure = []
for root, dirs, files in os.walk(directory):
for file in files:
file_path = os.path.join(root, file)
if not should_exclude(file_path):
relative_path = os.path.relpath(file_path, directory)
structure.append({
'path': relative_path,
'content': read_file_content(file_path)
})
return structure
def export_project_structure(root_dir='.'):
if os.path.exists('project_structure.json'):
os.remove('project_structure.json')
project_structure = explore_directory(root_dir)
output = {
'project_structure': project_structure
}
with open('project_structure.json', 'w', encoding='utf-8') as f:
json.dump(output, f, indent=2)
if __name__ == "__main__":
export_project_structure()
print("Project structure exported to project_structure.json")