forked from RatPoison-dev/RatInstaller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile_tools.py
48 lines (42 loc) · 1.69 KB
/
compile_tools.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
import locales, utils, subprocess, os
from pathlib import Path
locales = locales.Locales()
def compile():
locales.advPrint("BUILDING")
subprocess.check_call(["gradlew.bat", "RatPoison"])
deleteLibsFolder()
utils.killJDKs()
bat_file = utils.getBatName()
for path in utils.searchFile("java.exe"):
if (utils.verifyPath(str(path))):
java_exe = str(path)
with open(bat_file, "r") as rFile:
prevLines = rFile.readlines()
prevLines[4] = prevLines[4].replace("java", f"\"{java_exe}\"", 1)
with open(bat_file, "w") as wFile:
wFile.writelines(prevLines)
break
if (locales.advInput("RANDOMIZE_FILE_NAMES_INPUT") in locales.YES):
randomize_file_names()
replace_bat_pathes()
def deleteLibsFolder():
for path in Path(os.getcwd()).rglob("libs"):
if len(listdir := os.listdir(strpath := str(path))) > 0 and "RatPoison" in listdir[0]:
utils.rmtree(strpath)
break
def randomize_file_names():
random_name = utils.getRandomName()
folder_name = utils.getFolderName()
for file in os.listdir(folder_name):
path_to_file = os.path.join(folder_name, file)
if (os.path.isfile(path_to_file)):
fileExt = os.path.splitext(file)[1]
os.rename(path_to_file, f"{folder_name}/{random_name}{fileExt}")
def replace_bat_pathes():
bat_file = utils.getBatName()
with open(bat_file, "r") as rFile:
prevLines = rFile.readlines()
jar_file = utils.getJarName()
prevLines[4] = f"{' '.join(prevLines[4].split(' ')[:-3])} \"{jar_file}\"\n"
with open(bat_file, "w") as wFile:
wFile.writelines(prevLines)