-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshow_structure.py
More file actions
70 lines (60 loc) · 1.62 KB
/
show_structure.py
File metadata and controls
70 lines (60 loc) · 1.62 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
import os
# ===== ADD ALL FOLDERS/FILES YOU WANT TO SKIP =====
IGNORE_DIRS = {
'__pycache__',
'.git',
'venv',
'env',
'.venv',
'.env',
'node_modules',
'.idea',
'.vscode',
'.mypy_cache',
'.pytest_cache',
'staticfiles',
'.tox',
}
IGNORE_FILES = {
'.pyc',
'.pyo',
'.sqlite3',
'.db',
'.DS_Store',
'Thumbs.db',
'.env',
}
IGNORE_EXACT_FILES = {
'db.sqlite3',
'.gitignore',
'show_structure.py',
'project_structure.txt',
}
def should_ignore_file(filename):
if filename in IGNORE_EXACT_FILES:
return True
for ext in IGNORE_FILES:
if filename.endswith(ext):
return True
return False
def show_tree(path='.', prefix=''):
entries = sorted(os.listdir(path))
# Filter out ignored directories and files
dirs = [e for e in entries
if os.path.isdir(os.path.join(path, e)) and e not in IGNORE_DIRS]
files = [e for e in entries
if os.path.isfile(os.path.join(path, e)) and not should_ignore_file(e)]
all_items = files + dirs
for i, item in enumerate(all_items):
is_last = (i == len(all_items) - 1)
connector = '└── ' if is_last else '├── '
if item in dirs:
print(f"{prefix}{connector}{item}/")
new_prefix = prefix + (' ' if is_last else '│ ')
show_tree(os.path.join(path, item), new_prefix)
else:
print(f"{prefix}{connector}{item}")
if __name__ == '__main__':
project_name = os.path.basename(os.path.abspath('.'))
print(f"{project_name}/")
show_tree('.')