-
Notifications
You must be signed in to change notification settings - Fork 4
/
project_setup.py
63 lines (47 loc) · 1.5 KB
/
project_setup.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
59
60
61
62
63
import stat
from os import W_OK, access, chmod, environ, remove, rename
from os.path import isdir, join
from shutil import rmtree
from subprocess import run
def onexc(func, path, exc_info):
if not access(path, W_OK):
chmod(path, stat.S_IWUSR)
func(path)
else:
raise
# Remove original git repo
if isdir(".git"):
rmtree(".git", onexc=onexc)
# Remove README.md
remove("README.md")
# Get project name and author
project_name = input("Enter project name: ")
author = input("Enter author: ")
print()
# Update CMakeLists.txt
with open("CMakeLists.txt", "r", encoding="utf-8") as f:
cmakelists = f.read()
cmakelists = cmakelists.replace("PluginName", project_name)
cmakelists = cmakelists.replace("AuthorName", author)
cmakelists = cmakelists.replace("0.0.1", "1.0.0")
with open("CMakeLists.txt", "w", encoding="utf-8") as f:
f.write(cmakelists)
# Rename ini file
rename(
join("contrib", "Config", "PluginName.ini"),
join("contrib", "Config", f"{project_name}.ini"),
)
# Update Settings.cpp
with open(join("src", "Settings.cpp"), "r", encoding="utf-8") as f:
settings_cpp = f.read()
settings_cpp = settings_cpp.replace("PluginName.ini", f"{project_name}.ini")
with open(join("src", "Settings.cpp"), "w", encoding="utf-8") as f:
f.write(settings_cpp)
# Update baselines
print("Updating vcpkg.json baselines...")
run([f"{environ["VCPKG_ROOT"]}/vcpkg.exe", "x-update-baseline"])
print()
# Initialize empty git repo
run(["git", "init"])
# Self-destruct
remove(__file__)