-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.py
62 lines (58 loc) · 2.23 KB
/
install.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
from os import environ
from winreg import *
from urllib.request import urlretrieve
from subprocess import run
python_install_key=R'SOFTWARE\Python\PythonCore\3.6\InstallPath'
python_url_64='https://www.python.org/ftp/python/3.6.8/python-3.6.8-amd64.exe'
python_url_32='https://www.python.org/ftp/python/3.6.8/python-3.6.8.exe'
python_installer_args=' /passive Include_launcher=0 AssociateFiles=0 Shortcuts=0'
is64='64' in environ['PROCESSOR_ARCHITECTURE'] or '64' in environ['PROCESSOR_ARCHITEW6432']
global_ini_path=environ['appdata']+'/obs-studio/global.ini'
install_path=None
def ensureInstallPath()->str:
print('Searching for conflicting python installs')
try:
install_path=QueryValue(HKEY_LOCAL_MACHINE, python_install_key)
print('System python 3.6 found')
return install_path
except:
print('System python 3.6 not found')
try:
install_path=QueryValue(HKEY_CURRENT_USER, python_install_key)
print('User python 3.6 found')
return install_path
except:
print('User python 3.6 not found')
print('downloading python')
python_installer=None
if is64:
python_installer=urlretrieve(python_url_64)[0]
else:
python_installer=urlretrieve(python_url_32)[0]
print('Installing python')
run(python_installer+python_installer_args)
return QueryValue(HKEY_CURRENT_USER, python_install_key)
def main():
input('Make sure OBS is closed, then press enter to continue.')
install_path=ensureInstallPath()
print('Using '+install_path)
print('Updating OBS config')
from configparser import ConfigParser
config=ConfigParser(strict=False)
global_ini=open(global_ini_path,'r+',encoding='utf-8')
config.read_string(global_ini.read().replace('\ufeff',''))
if is64:
keyname='path64bit'
else:
keyname='path32bit'
if config.has_section('Python'):
config['Python'][keyname]=install_path
else:
config['Python']={keyname:install_path}
global_ini.seek(0)
global_ini.truncate()
config.write(global_ini,space_around_delimiters=False)
global_ini.close()
input('\nOBS can now use python 3.6 scripts\nYou can close this window\nor press enter to exit')
if __name__ == '__main__':
main()