Skip to content

Commit d0aa3a5

Browse files
committed
made a tool to build releases
1 parent a7199af commit d0aa3a5

3 files changed

Lines changed: 155 additions & 2 deletions

File tree

FT_Builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def print_ascii_art():
1717
(__) (__) (____/\____/(__)\____/(____/(____)(__\_)
1818
"""
1919
credits = r"""
20-
Made By Hash - v1.2
20+
Made By Hash - vVersionNumber
2121
2222
2323
"""

PythonPatcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def print_ascii_art():
1414
(__) \_/\_/ \___)(____) (__) (__\_)\_/\_/ \___)(__\_)(__)\_)__) \___/ (__) \_/\_/(__) \___)\_)(_/(____)(__\_)
1515
"""
1616
credits = r"""
17-
Made By Hash - v1.2
17+
Made By Hash - vVersionNumber
1818
1919
2020
"""

ReleaseBundler.py

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
import os
2+
from pickle import TRUE
3+
import tkinter as tk
4+
from tkinter import filedialog
5+
import sys
6+
import shutil
7+
8+
def print_ascii_yippie():
9+
ascii_art = r"""
10+
11+
12+
13+
14+
15+
16+
17+
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
_ _ __ ____ ____ __ ____
28+
( \/ )( )( _ \( _ \( )( __)
29+
) / )( ) __/ ) __/ )( ) _)
30+
(__/ (__)(__) (__) (__)(____)
31+
"""
32+
33+
print(ascii_art)
34+
35+
def custom_ignore(dir, contents):
36+
exclude_files = ["ReleaseBundler.py" ,"FT_Builder.py", "PythonPatcher.py", "README.md", ".gitattributes"]
37+
exclude_folders = [".github", ".git"] # List of folder names to exclude
38+
ignored = set()
39+
40+
for item in contents:
41+
item_path = os.path.join(dir, item)
42+
43+
# Check if it's a directory and if it's one of the folders to exclude
44+
if os.path.isdir(item_path):
45+
if item in exclude_folders:
46+
ignored.add(item)
47+
else: # It's a file
48+
if item in exclude_files:
49+
ignored.add(item)
50+
51+
return ignored
52+
53+
def copy_directory(source_dir, destination_dir):
54+
try:
55+
for root, dirs, files in os.walk(source_dir):
56+
# Use the custom_ignore function to exclude files and folders
57+
ignored = custom_ignore(root, dirs + files)
58+
for item in ignored:
59+
if os.path.isdir(os.path.join(root, item)):
60+
dirs.remove(item)
61+
else:
62+
files.remove(item)
63+
64+
for file in files:
65+
src_file = os.path.join(root, file)
66+
dest_file = os.path.join(destination_dir, os.path.relpath(src_file, source_dir))
67+
os.makedirs(os.path.dirname(dest_file), exist_ok=True)
68+
shutil.copy2(src_file, dest_file)
69+
70+
print(f"Successfully copied from '{source_dir}' to '{destination_dir}'")
71+
except Exception as e:
72+
print(f"An error occurred: {str(e)}")
73+
74+
def delete_files_in_directory(directory_path):
75+
try:
76+
# Check if the directory exists
77+
if os.path.exists(directory_path):
78+
# Iterate over all files and subdirectories in the directory
79+
for root, dirs, files in os.walk(directory_path, topdown=False):
80+
for file_name in files:
81+
file_path = os.path.join(root, file_name)
82+
os.remove(file_path) # Delete the file
83+
for dir_name in dirs:
84+
dir_path = os.path.join(root, dir_name)
85+
shutil.rmtree(dir_path) # Delete the subdirectory and its contents
86+
shutil.rmtree(directory_path)
87+
print(f"generated custom folder deleted")
88+
else:
89+
print(f"no custom folder found")
90+
except Exception as e:
91+
print(f"An error occurred while deleting the files in the custom folder, error: {e}")
92+
93+
94+
#fonction that will take care of modifying the right lines of code in the patcher
95+
def ModifyVersionNumber(VersionNumber, RepoDir, DestDir, fileName):
96+
with open(os.path.join(RepoDir, fileName), 'r', encoding='utf-8') as file:
97+
script_content = file.read()
98+
99+
script_content = script_content.replace(
100+
'VersionNumber',
101+
f'{VersionNumber}' # Remove the surrounding double quotes
102+
)
103+
104+
with open(os.path.join(DestDir, fileName), 'wb') as file:
105+
encoded_content = script_content.encode('utf-8')
106+
file.write(encoded_content)
107+
108+
print("replaced version number")
109+
110+
111+
112+
def zip_folder(source_dir, zip_filename):
113+
try:
114+
shutil.make_archive(zip_filename, 'zip', source_dir)
115+
print(f"Successfully zipped '{source_dir}' to '{zip_filename}.zip'")
116+
except Exception as e:
117+
print(f"An error occurred: {str(e)}")
118+
119+
120+
121+
def get_directory_path(prompt):
122+
root = tk.Tk()
123+
root.withdraw() # Hide the main window
124+
125+
directory_path = filedialog.askdirectory(title=prompt)
126+
127+
return directory_path
128+
129+
def main():
130+
os.environ['PYTHONIOENCODING'] = 'utf-8'
131+
Version_Number = input("Please input the version of the release: ")
132+
133+
#RepoDir = get_directory_path("please select where you have your repo")
134+
RepoDir = os.path.dirname(__file__)
135+
136+
DestDir = get_directory_path("please select where you want your release to be built")
137+
138+
TempDir = os.path.abspath(os.path.join(os.path.dirname(__file__), "temp"))
139+
os.makedirs(TempDir, exist_ok=True)
140+
141+
copy_directory(RepoDir, TempDir)
142+
ModifyVersionNumber(Version_Number, RepoDir, TempDir,"FT_Builder.py")
143+
ModifyVersionNumber(Version_Number, RepoDir, TempDir,"PythonPatcher.py")
144+
zip_folder(TempDir, "Face-Tracking-Patcher-V"+Version_Number)
145+
shutil.move("Face-Tracking-Patcher-V"+Version_Number+".zip", DestDir)
146+
delete_files_in_directory(TempDir)
147+
print_ascii_yippie()
148+
149+
150+
151+
152+
if __name__ == "__main__":
153+
main()

0 commit comments

Comments
 (0)