-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerateProjectShort.py
More file actions
99 lines (84 loc) · 4.1 KB
/
Copy pathGenerateProjectShort.py
File metadata and controls
99 lines (84 loc) · 4.1 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import os
from pathlib import Path
# List of directories and files to ignore
IGNORE_LIST = [
".git",
".idea",
"venv",
".venv",
"__pycache__",
"node_modules",
"target",
"build",
"dist",
"ProjectOneFile.txt", # self ignore
"GenerateProjectShort.py" # self ignore
]
def walk_dir(root_dir, prefix="", ignore_list=IGNORE_LIST):
contents = sorted(os.listdir(root_dir))
paths = [os.path.join(root_dir, p) for p in contents]
dirs = [p for p in paths if os.path.isdir(p) and os.path.basename(p) not in ignore_list]
files = [p for p in paths if os.path.isfile(p) and os.path.basename(p) not in ignore_list]
lines = []
for d in dirs:
lines.append(f"{prefix}├── {os.path.basename(d)}/")
lines.extend(walk_dir(d, prefix + "│ ", ignore_list))
for f in files:
if f != files[-1]:
lines.append(f"{prefix}├── {os.path.basename(f)}")
else:
lines.append(f"{prefix}└── {os.path.basename(f)}")
return lines
def get_project_structure(root_dir, root_dir_display, ignore_list=IGNORE_LIST):
return "\n".join([os.path.basename(root_dir_display) + "/"] + walk_dir(root_dir, ignore_list=ignore_list))
def get_readable_files(root_dir, readable_extensions, ignore_list=IGNORE_LIST):
file_data = []
for root, _, files in os.walk(root_dir):
for filename in files:
filepath = os.path.join(root, filename)
extension = os.path.splitext(filepath)[1]
if extension in readable_extensions and not any(ignored in filepath for ignored in ignore_list):
with open(filepath, "r", encoding="utf-8") as f:
content = f.read()
file_data.append(
(os.path.splitext(filepath)[0].replace(root_dir, "").replace("\\", "/"), content, extension[1:]))
return file_data
def generate_report(output_file, script_file, readable_extensions, ignore_list=IGNORE_LIST):
root_dir = "."
root_dir_display = str(Path(__file__).parent.name)
with open(output_file, "w", encoding="utf-8") as f:
f.write("Project structure:\n\n")
f.write(get_project_structure(root_dir, root_dir_display, ignore_list))
f.write("\n\n\nProject files:\n\n")
for filepath, content, extension in get_readable_files(root_dir, readable_extensions, ignore_list):
full_filepath = filepath + "." + extension
if content and script_file not in full_filepath and output_file not in full_filepath:
filepath_with_dots = filepath.replace("\\", ".")[1:]
f.write(f"{filepath_with_dots}.{extension}\n")
f.write(f"```{extension}\n{content}\n```\n\n\n")
if __name__ == "__main__":
output_file = "ProjectOneFile.txt"
readable_extensions = [
".txt", ".java", ".html", ".css", ".js", # Source extensions
# Programming languages
".py", ".c", ".cpp", ".cs", ".go", ".php", ".rb", ".swift", ".kts", ".rs",
".scala", ".pl", ".hs", ".clj", ".exs", ".erl", ".groovy", ".lua", ".r",
".pas", ".m", ".v", ".fs", ".jl", ".dart", ".kt", ".cl", # Added languages
# Scripting languages
".sh", ".bash", ".bat", ".ps1", ".awk", ".perl", # Added scripting languages
# Configuration files
".json", ".xml", ".yaml", ".properties", ".ini", ".toml", ".cfg", ".conf",
".env", ".plist", ".gradle", ".sbt", # Added config files
# Markup and documentation
".md", ".markdown", ".rst", ".adoc", ".tex", ".org", ".doxygen", # Added documentation formats
# Logs and data
".log", ".csv", ".tsv", ".sql", ".sqlite", ".avro", ".parquet", # Added data formats
# Other
".gitignore", ".dockerfile", ".makefile", ".cmake", ".qml", # Added other file types
".graphql", ".proto", ".tf", ".tfstate", # Infrastructure as Code
".webmanifest", ".svg", # Web
".eml", ".mbox" # Email
]
script_file = os.path.basename(__file__)
generate_report(output_file, script_file, readable_extensions)
print(f"Project analysis report generated in: {output_file}")