hhacks/houy.py
2020-01-26 11:52:47 +01:00

110 lines
3.4 KiB
Python
Executable File

#!/usr/bin/python3
from subprocess import call
from sys import argv, platform, exit, stderr
from os import environ, getenv, chdir
import shlex
import subprocess
from pathlib import Path
def enter_hfs():
if '-hfs' not in argv:
print('__ HouY __')
hfs = getenv('HFS')
if not hfs:
print('Houdini Environment not yet initialized. Boostraping...', file=stderr)
hfsen = {
'darwin': Path('/Applications/Houdini').glob('Houdini*/Frameworks/Houdini.framework/Versions/Current/Resources'),
'linux': Path('/opt').glob('hfs*'),
'win32': Path(r'C:\Program Files\Side Effects Software').glob('Houdini *'),
}
if platform not in hfsen.keys():
print('Platform `{}` not supported... yet.'.format(platform), file=stderr)
exit(1)
if hfsen.get(platform):
h = list(hfsen[platform])
print('HFS environment found: ', ', '.join(f.name for f in h), '*', sep='')
hfs = h[-1]
else:
print("ERROR - couldn't find HFS")
exit(1)
if platform == 'win32' and '-hfs' not in argv:
argv.append('-hfs')
call([str(hfs/"bin/hcmd.exe"), '/c', *argv])
exit()
print('Current HFS:', hfs)
chdir(hfs)
return hfs
def init_opencl():
environ.update({
'HOUDINI_OCL_DEVICETYPE': 'GPU',
'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('plugins/houdini/[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:
print('Redshift: no plugins found')
else:
print('Redshift not found')
def init_faststart():
environ.update({
'HOUDINI_NO_SPLASH': '1',
'HOUDINI_DSO_ERROR': '2',
})
def init_remote_gl():
if platform == 'win32':
print()
print('For OpenGL support remotely run this as an administrator:')
print(r'c:\Windows\System32\tscon.exe {} /dest:console'.format(getenv('SessionName')))
def init_env():
# Initialize env vars.
if platform != 'win32':
command = shlex.split("env -i sh -c '. houdini_setup >/dev/null && env'")
proc = subprocess.Popen(command, stdout=subprocess.PIPE,
universal_newlines=True)
for line in proc.stdout:
(key, _, value) = str(line.strip()).partition('=')
environ[key] = value
print(key, '=', value)
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)