-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
53 lines (46 loc) · 1.53 KB
/
build.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
from winreg import *
from os.path import join,abspath,dirname
from subprocess import run
from sys import path
hives=[
HKEY_LOCAL_MACHINE,
HKEY_CURRENT_USER
]
roots=[
R'SOFTWARE\WOW6432Node\Python',
R'SOFTWARE\Python'
]
def getPythonPath()->str:
print('Searching for Python installs')
for hive in hives:
for root in roots:
try:
rootKey=OpenKey(hive, root)
companyCount=QueryInfoKey(rootKey)[0]
for companyIndex in range(companyCount):
companyName=EnumKey(rootKey, companyIndex)
companyKey=OpenKey(rootKey, companyName)
tagCount=QueryInfoKey(companyKey)[0]
for tagIndex in range(tagCount):
tagName=EnumKey(companyKey, tagIndex)
tagKey=OpenKey(companyKey, tagName)
pythonPath=join(QueryValue(tagKey, 'InstallPath'),'python.exe')
print('Using '+pythonPath)
return pythonPath
except:
pass
def installPyInstaller(python:str):
print('Installing/Updating PyInstaller')
command=python+' -m pip install pyinstaller --user'
run(command)
def build(python:str)->int:
return run(python+' -m PyInstaller -F install.py').returncode
def main():
python=getPythonPath()
try:
assert build(python)==0
except:
installPyInstaller(python)
return build(python)
if __name__ == '__main__':
exit(main())