-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrun_usd.py
103 lines (77 loc) · 3.08 KB
/
run_usd.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"""
Python 2 and 3 version
This will setup an appropriate OS environment to run Python USD scripts from usdzconvert script path
"""
from __future__ import print_function
import os
import sys
from subprocess import Popen
DEBUG = 1 # Print Environment info
def join(*args):
return os.path.join(*args)
def update_path_string(env, key, new_path):
if not os.path.exists(new_path):
print('Skipping non-existing path:', new_path)
return
env_path_string = env.get(key, '')
if DEBUG:
print('Extending {} with: {}'.format(key, os.path.abspath(new_path)))
if not env_path_string:
env[key] = os.path.abspath(new_path) + os.pathsep
elif env_path_string[-1:] == os.pathsep:
env[key] = env_path_string + os.path.abspath(new_path) + os.pathsep
else:
env[key] = env_path_string + os.pathsep + os.path.abspath(new_path) + os.pathsep
def create_usd_env():
base = join(os.path.dirname(__file__), 'USD')
usd_lib = join(base, 'lib')
usd_bin = join(base, 'bin')
usd_plg = join(base, 'plugin', 'usd')
usd_python_lib = join(base, 'lib', 'python')
# Unix specific
ld_lib = join(base, 'lib64')
# Windows specific portable python2.7 interpreter and p2.7 modules
_deps = join(base, 'deps')
python_deps = join(_deps, 'python')
usdview_python_deps = join(_deps, 'usdview-deps-python')
usdzconvert_python_path = join(os.path.dirname(__file__), 'usdzconvert')
# Create a copy of the actual os environment
env = dict()
env.update(os.environ)
if sys.platform == 'win32':
env['PATH'] = str() # This will not work on Unix, it would no longer find the python executable
if not os.path.exists(base):
return env
# Update LD_LIBRARY_PATH
if os.path.exists(ld_lib):
update_path_string(env, 'LD_LIBRARY_PATH', ld_lib)
# Update PYTHONPATH
for p in (usdzconvert_python_path, usdview_python_deps, usd_python_lib):
update_path_string(env, 'PYTHONPATH', p)
# Update PATH
for p in (python_deps, usd_lib, usd_bin, usd_plg):
update_path_string(env, 'PATH', p)
return env
if __name__ == '__main__':
if DEBUG:
print(sys.argv)
usd_env = create_usd_env()
if sys.platform == 'win32':
py_path = join(os.path.dirname(__file__), 'USD', 'deps', 'python', 'python.exe') # Python 2.7
arguments = [os.path.abspath(py_path)]
else:
arguments = ['python2.7']
if not len(sys.argv) > 1:
print("##########################################################################")
print("No arguments provided, running python2.7 interpreter with USD environment.")
print("##########################################################################")
p = Popen(arguments, env=usd_env)
out, error = p.communicate()
sys.exit(p.returncode)
for arg in sys.argv[1:]:
# Omit first argument which will be path to this script file
print(arg)
arguments.append(arg)
p = Popen(arguments, env=usd_env)
out, error = p.communicate()
sys.exit(p.returncode)