#!/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('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 welcome_redshift(): if platform == 'win32': if '-rs3' in argv: redshift_path = 'C:/ProgramData/Redshift3' else: redshift_path = 'C:/ProgramData/Redshift' else: if '-rs3' in argv: 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) environ.update({ 'HOUDINI_NO_SPLASH': '1', '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), }) 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'))) # 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() call(['./bin/houdini'], env=environ)