-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsysutils.py
More file actions
160 lines (104 loc) · 3.92 KB
/
Copy pathsysutils.py
File metadata and controls
160 lines (104 loc) · 3.92 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
"""
PHI
7/8/2025
Phi C++ Project
sysutils.py
Zevi Berlin
"""
from datetime import datetime
from os import path, makedirs, system
def create_code_files(header_parent_dir: str, filename: str, author_name: str) -> None:
author_name = "Zevi Berlin" if not author_name else author_name
cap_name: str = filename.upper()
date: str = str(datetime.now()).split(" ")[0].replace("-", "/")
header_path: str = f"include/{header_parent_dir + '/' if header_parent_dir else ''}{filename}.hpp"
header_content: str = f"""/*
PHI
{date}
Phi C++ Project
{header_path}
{author_name}
*/
#ifndef {cap_name}_HPP
#define {cap_name}_HPP
#endif /* {cap_name}_HPP */
"""
makedirs(f"include/{header_parent_dir}", exist_ok=True)
if path.exists(header_path) and path.getsize(header_path) > 0:
print(f"Header file '{header_path}' already exists and has content.")
if input("Would you like to erase and rewrite it (y/n)? ") not in ["y", "Y", "yes", "YES", "1", 1]:
print("\nExiting.")
exit(0)
with open(header_path, "w") as header:
header.write(header_content)
source_path: str = f"src/{filename}.cpp"
source_content: str = f"""/*
PHI
{date}
Phi C++ Project
{source_path}
{author_name}
*/
#include "{header_parent_dir + '/' if header_parent_dir else ''}{filename}.hpp"
"""
if path.exists(source_path) and path.getsize(source_path) > 0:
print(f"Source file '{source_path}' already exists and has content.")
if input("Would you like to erase and rewrite it (y/n)? ") not in ["y", "Y", "yes", "YES", "1", 1]:
print("\nExiting.")
exit(0)
with open(source_path, "w") as source:
source.write(source_content)
#########################
#########################
def main():
menu: str = """OPTIONS:
1) Create Code Files
Add a source file and corresponding header file. Also boilerplates with include guards and header comment.
2) Build (Release)
3) Build (Debug)
4) Cleanup
5) Format
6) Analyze
7) Exit
"""
print(menu)
match (x := int(input("\n >> "))):
case 1:
header_parent_dir = input("Header Parent Dir (e.g 'data' for path 'include/data/'): ")
filename = input("Filename (do not include .cpp/.hpp): ")
author_name = input("Your name (defaults to Zevi Berlin): ")
create_code_files(header_parent_dir, filename, author_name)
print("\nSUCCESSFULLY CREATED AND BOILERPLATED FILES")
case 2:
system("cmake -S . -B _build -DCMAKE_BUILD_TYPE=Release")
if input("Continue? ") != "y": exit(1)
system("cmake --build _build -j4")
system("mv _build/phi ./")
case 3:
system("cmake -S . -B _build -DCMAKE_BUILD_TYPE=Debug")
if input("Continue? ") != "y": exit(1)
system("cmake --build _build -j4")
system("mv _build/phi ./")
system("dsymutil ./phi")
case 4:
system("mv _build/compile_commands.json ./")
system("rm -rf _build/")
system("mkdir _build")
system("mv ./compile_commands.json _build/")
system("rm -rf phi phi.dSYM .cache")
case 5:
system("find src -type f \\( -name \"*.c\" -o -name \"*.cpp\" \\) -exec clang-format -i {} +")
system("find include -type f \\( -name \"*.h\" -o -name \"*.hpp\" \\) -exec clang-format -i {} +")
case 6:
system("find src -type f \\( -name \"*.c\" -o -name \"*.cpp\" \\) -exec clang-tidy --config-file=./.clang-tidy --format-style=file -p _build {} +")
case 7:
print("\nExiting.")
case _:
print(f"Input '{x}' not recognized.")
exit(1)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("\nExiting.")
exit(0)