-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcpp-template-installer.py
63 lines (49 loc) · 1.78 KB
/
cpp-template-installer.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 sys
from subprocess import call
from shutil import rmtree
from os import remove, chmod, unlink
from stat import S_IWRITE
def replaceTextInFile(filePath, old, new):
file = open(filePath, 'r')
fileData = file.read()
file.close()
fileData = fileData.replace(old, new)
file = open(filePath, 'w')
file.write(fileData)
file.close()
def on_rm_error(func, path, exc_info):
# path contains the path of the file that couldn't be removed
# let's just assume that it's read-only and unlink it.
chmod(path, S_IWRITE)
unlink(path)
if len(sys.argv) != 2:
print("Please provide the project name as the only argument")
sys.exit(1)
projectName = sys.argv[1]
print("==> Cloning cpp-template into {0}".format(projectName))
status = call([
"git", "clone", "--recursive",
"https://github.com/joshpeterson/cpp-template.git", projectName])
if status != 0:
sys.exit(status)
gitDirectory = "{0}/.git".format(projectName)
print("==> Removing the {0} directory".format(gitDirectory))
rmtree("{0}".format(gitDirectory), onerror=on_rm_error)
print("==> Changing the project name to {0}".format(projectName))
replaceTextInFile(
"{0}/CMakeLists.txt".format(projectName), "cpp-template", projectName)
replaceTextInFile(
"{0}/tools/build-win32-debug.bat".format(projectName), "cpp-template",
projectName)
replaceTextInFile(
"{0}/tools/build-win32-release.bat".format(projectName),
"cpp-template", projectName)
replaceTextInFile(
"{0}/tools/build-win64-debug.bat".format(projectName),
"cpp-template", projectName)
replaceTextInFile(
"{0}/tools/build-win64-release.bat".format(projectName),
"cpp-template", projectName)
readmeFile = "{0}/README.md".format(projectName)
print("==> Removing {0}".format(readmeFile))
remove(readmeFile)