-
Notifications
You must be signed in to change notification settings - Fork 0
/
startBoilerplate.py
130 lines (110 loc) · 4.47 KB
/
startBoilerplate.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
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
import os
import re
import sys
import urllib.request
import zipfile
import shutil
from distutils.dir_util import copy_tree
args = sys.argv
dryRun = len(args) > 1 and args[1].lower() == "true"
folder = os.getcwd()
folderPrintIndex = folder.rfind("/")
folderPrint = folder[folderPrintIndex:]
os.system("clear")
print(f"""
_____ _ ____ _ _ _ _ ___ _ _ _ _ _ _
| ___|__ _ _ _ __ __| |_ __ _ _ | __ ) ___ (_) | ___ _ __ _ __ | | __ _| |_ ___ |_ _|_ __ (_) |_(_) __ _| (_)______ _| |_ ___ _ __
| |_ / _ \| | | | '_ \ / _` | '__| | | | | _ \ / _ \| | |/ _ \ '__| '_ \| |/ _` | __/ _ \ | || '_ \| | __| |/ _` | | |_ / _` | __/ _ \| '__|
| _| (_) | |_| | | | | (_| | | | |_| | | |_) | (_) | | | __/ | | |_) | | (_| | || __/ | || | | | | |_| | (_| | | |/ / (_| | || (_) | |
|_| \___/ \__,_|_| |_|\__,_|_| \__, | |____/ \___/|_|_|\___|_| | .__/|_|\__,_|\__\___| |___|_| |_|_|\__|_|\__,_|_|_/___\__,_|\__\___/|_|
|___/ |_|
Created by: Cussa Mitre
Discord: CussaMitre
Github: https://github.com/Cussa
Dry run activate: {dryRun}
{"Changes will not be saved." if dryRun else "Changes will be saved to the files."}
All changes are case sensitive.
""")
extensions = [ "", ".md", ".txt"]
specialFiles = {
"README": "",
"LICENSE": "",
"CHANGELOG": ""
}
if os.path.exists("system.json"):
print("- system.json found! Will not download the boilerplate!")
else:
for key in specialFiles.keys():
for extension in extensions:
currentFile = f"{key}{extension}"
if os.path.exists(currentFile):
newFile = f'{key}_ORIGINAL{extension}'
specialFiles[key] = newFile
os.rename(currentFile, newFile)
break
print("- Downloading boilerplate system")
urllib.request.urlretrieve("https://gitlab.com/asacolips-projects/foundry-mods/boilerplate/-/archive/master/boilerplate-master.zip", "boilerplate.zip")
with zipfile.ZipFile("boilerplate.zip", 'r') as zip_ref:
zip_ref.extractall(folder)
copy_tree("boilerplate-master", folder)
shutil.rmtree("boilerplate-master")
os.remove("boilerplate.zip")
for key, value in specialFiles.items():
if not value:
continue
for extension in extensions:
currentFile = f"{key}{extension}"
if os.path.exists(currentFile):
os.rename(currentFile, f'{key}_BOILERPLATE{extension}')
break
os.rename(value, value.replace("_ORIGINAL", ""))
systemName = input("Replace Boilerplate by => ")
boilerplateLowercase = systemName.lower() # input("boilerplate => ")
boilerplateUppercase = systemName.upper() # input("BOILERPLATE => ")
boilerplateCapitalize = systemName.capitalize() # input("Boilerplate => ")
changes = {
"boilerplate": boilerplateLowercase,
"BOILERPLATE": boilerplateUppercase,
"Boilerplate": boilerplateCapitalize,
}
skipList = [
r".*/\.DS_Store.*",
r".*\.git.*",
r".*\.png.*",
r".*/lib.*",
r".*startBoilerplate\.py.*",
r".*package-lock\.json.*"
]
def checkFileProcess(filepath):
for pattern in skipList:
if bool(re.match(pattern, filepath)):
return False
return True
def replaceInFile(filePath):
# Read in the file
with open(filePath, 'r') as file:
filedata = file.read()
# Replace the target string
newFileData = filedata
for source, destiny in changes.items():
newFileData = newFileData.replace(source, destiny)
# Write the file out again if they are different
if newFileData != filedata:
if not dryRun:
with open(filePath, 'w') as file:
file.write(newFileData)
print(f'Changing content for: {filePath[folderPrintIndex:]}')
pathiter = (os.path.join(root, filename)
for root, _, filenames in os.walk(folder)
for filename in filenames
)
for path in pathiter:
if checkFileProcess(path):
fileName = path[folderPrintIndex+len(folderPrint)+1:]
replaceInFile(path)
newname = path.replace("boilerplate", changes["boilerplate"])
if newname != path:
if not dryRun:
os.rename(path,newname)
print(f'Renamin file from "{path[folderPrintIndex:]}" to "{newname[folderPrintIndex:]}"')
os.remove(args[0])