-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheasy_python_quick_compiler.py
72 lines (49 loc) · 1.82 KB
/
easy_python_quick_compiler.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
import os
import shutil
def remove_folder(folder_name):
if os.path.exists(folder_name):
shutil.rmtree(folder_name)
def create_folder(folder_name):
if not os.path.exists(folder_name):
os.makedirs(folder_name)
def delete_file(file_name):
if os.path.exists(file_name):
os.remove(file_name)
def dot_py_to_dot_exe(string):
return f'{string.split(".")[0]}.exe'
def file_path_to_file(string):
return string.split("\\").pop()
def delete_ends_with(directory,string_endswith):
files = os.listdir(directory)
for file2 in files:
if file2.endswith(f".{string_endswith}"):
os.remove(file2)
def remote_compile(file):
command = f'pyinstaller --noconfirm --onefile --console "{file}"'
print(f'running command:\n{command}')
os.system(command)
with open(dot_py_to_dot_exe(f'dist/{file_path_to_file(file)}'), 'rb') as f:
binary = f.read()
remove_folder('dist')
remove_folder('build')
delete_ends_with(os.getcwd(), 'spec')
return binary
def local_compile(file):
dir = f'"{os.getcwd()}\\{file}"'
command = f'pyinstaller --noconfirm --onefile --console {dir}'
print(f'running command:\n{command}')
os.system(command)
with open(dot_py_to_dot_exe(f'dist/{file}'), 'rb') as f:
binary = f.read()
remove_folder('dist')
remove_folder('build')
return binary
file = input('Enter file path of file to compile, or only file name if file is in the same directory as me:\n')
if '\\' in file:
with open(dot_py_to_dot_exe(file), 'wb') as f:
f.write(remote_compile(file))
print(f'Compiled file was saved to {dot_py_to_dot_exe(file)}')
else:
with open(dot_py_to_dot_exe(file), 'wb') as f:
f.write(local_compile(file))
print(f'Compiled file was saved to {os.getcwd()}\\{dot_py_to_dot_exe(file)}')