Refactor initialization

This commit is contained in:
Kuba Winnicki 2019-10-14 15:55:34 +01:00
parent 9aabe09269
commit b70c24b110

70
houy.py
View File

@ -1,6 +1,5 @@
#!/usr/bin/python3 #!/usr/bin/python3
from subprocess import call from subprocess import call
from sys import argv, platform, exit, stderr from sys import argv, platform, exit, stderr
from os import environ, getenv, chdir from os import environ, getenv, chdir
@ -25,7 +24,7 @@ def enter_hfs():
exit(1) exit(1)
if hfsen.get(platform): if hfsen.get(platform):
h = list(hfsen[platform]) h = list(hfsen[platform])
print('Found: ', ', '.join(f.name for f in h), '*', sep='') print('HFS environment found: ', ', '.join(f.name for f in h), '*', sep='')
hfs = h[-1] hfs = h[-1]
else: else:
print("ERROR - couldn't find HFS") print("ERROR - couldn't find HFS")
@ -40,40 +39,53 @@ def enter_hfs():
chdir(hfs) chdir(hfs)
return hfs return hfs
def welcome_redshift(): def init_opencl():
if platform == 'win32': environ.update({
if '-rs3' in argv: 'HOUDINI_OCL_DEVICETYPE': 'GPU',
redshift_path = 'C:/ProgramData/Redshift3' 'HOUDINI_OCL_DEVICENUMBER': '0',
})
def init_redshift(ver=0):
global plugins, redshift_path
rs_path = {
'linux': Path('/').glob('*/redshift' + (ver and str(ver) or '')),
'win32': Path(r'C:/ProgramData').glob('Redshift*'),
}
rs_path['darwin'] = rs_path['linux']
# choose version
paths = [p for p in rs_path[platform]]
if paths:
redshift_path = paths[0]
print('Redshift found:',str(redshift_path))
plugins = sorted(redshift_path.glob('redshift4houdini/[1-9]*'))
if plugins:
plugin = str(plugins[-1])
print('Redshift plugins found:', plugin)
environ.update({
'PATH': ';'.join(['{}/bin'.format(str(redshift_path)),
environ.get('PATH')]),
'REDSHIFT_COREDATAPATH': str(redshift_path),
'HOUDINI_PATH': "{};&".format(plugin),
})
else: else:
redshift_path = 'C:/ProgramData/Redshift' print('Redshift: no plugins found')
else: else:
if '-rs3' in argv: print('Redshift not found')
redshift_path = '/opt/redshift3'
else:
redshift_path = '/opt/redshift'
return redshift_path
if __name__ == '__main__':
enter_hfs()
redshift_path = welcome_redshift()
if redshift_path:
print('Redshift:', redshift_path)
def init_faststart():
environ.update({ environ.update({
'HOUDINI_NO_SPLASH': '1', 'HOUDINI_NO_SPLASH': '1',
'HOUDINI_DSO_ERROR': '2', 'HOUDINI_DSO_ERROR': '2',
'PATH': ';'.join(['{}/bin'.format(redshift_path),
environ.get('PATH')]),
'REDSHIFT_COREDATAPATH': redshift_path,
'HOUDINI_OCL_DEVICETYPE': 'GPU',
'HOUDINI_OCL_DEVICENUMBER': '0',
'HOUDINI_PATH': "{}/Plugins/Houdini/17.5.173;&".format(redshift_path),
}) })
def init_remote_gl():
if platform == 'win32': if platform == 'win32':
print() print()
print('For OpenGL support remotely run this as an administrator:') print('For OpenGL support remotely run this as an administrator:')
print(r'c:\Windows\System32\tscon.exe {} /dest:console'.format(getenv('SessionName'))) print(r'c:\Windows\System32\tscon.exe {} /dest:console'.format(getenv('SessionName')))
def init_env():
# Initialize env vars. # Initialize env vars.
if platform != 'win32': if platform != 'win32':
command = shlex.split("env -i sh -c '. houdini_setup >/dev/null && env'") command = shlex.split("env -i sh -c '. houdini_setup >/dev/null && env'")
@ -84,4 +96,14 @@ if __name__ == '__main__':
environ[key] = value environ[key] = value
print(key, '=', value) print(key, '=', value)
proc.communicate() proc.communicate()
if __name__ == '__main__':
enter_hfs()
init_faststart()
init_opencl()
init_redshift()
init_remote_gl()
# init_env is not needed anymore
#init_env()
call(['./bin/houdini'], env=environ) call(['./bin/houdini'], env=environ)