forked from lunadigital/btoa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenviron.py
81 lines (63 loc) · 2.54 KB
/
environ.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
import bpy
import os
import sys
def is_preconfigured():
if "ARNOLD_ROOT" in os.environ:
return True
return False
def load_cached_arnold_path():
try:
path_to_cache = os.path.join(os.path.dirname(os.path.abspath(__file__)), "prefs")
f = open(path_to_cache, "r")
return f.readline()
except:
return ""
def save_cached_arnold_path(path):
path_to_cache = os.path.join(os.path.dirname(os.path.abspath(__file__)), "prefs")
sdk_path = os.path.abspath(bpy.path.abspath(path))
with open(path_to_cache, "w") as f:
f.write(sdk_path)
def configure_arnold_environment():
prefs = bpy.context.preferences.addons[__package__].preferences
if is_preconfigured():
path = os.getenv("ARNOLD_ROOT")
print("Arnold installation found: " + path)
else:
path = load_cached_arnold_path()
print("No Arnold installation found. Settings from preferences: " + path)
prefs.arnold_path = path
if path != "":
python_path = os.path.join(prefs.arnold_path, "python")
if python_path not in sys.path:
sys.path.append(python_path)
def configure_plugins():
addon_root = os.path.dirname(os.path.abspath(__file__))
drivers = os.path.join(addon_root, "drivers", "build")
if "ARNOLD_PLUGIN_PATH" in os.environ:
addon_root = os.path.dirname(os.path.abspath(__file__))
drivers = os.path.join(addon_root, "drivers", "build")
plugins = os.getenv("ARNOLD_PLUGIN_PATH").split(os.pathsep)
if drivers not in plugins:
os.environ["ARNOLD_PLUGIN_PATH"] += os.pathsep + drivers
else:
os.environ["ARNOLD_PLUGIN_PATH"] = drivers
def remove_plugins():
addon_root = os.path.dirname(os.path.abspath(__file__))
drivers = os.path.join(addon_root, "drivers", "build")
plugins = os.getenv("ARNOLD_PLUGIN_PATH").split(os.pathsep)
if len(plugins) > 1:
plugins.remove(drivers)
os.environ["ARNOLD_PLUGIN_PATH"] = os.pathsep.join(plugins)
else:
del os.environ["ARNOLD_PLUGIN_PATH"]
def get_default_ocio_config():
addon_root = os.path.dirname(os.path.abspath(__file__))
return os.path.join(addon_root, "config", "colormanagement", "config.ocio")
def configure_ocio():
if not "OCIO" in os.environ:
print("No custom OCIO config found, using default Filmic...")
os.environ["OCIO"] = get_default_ocio_config()
def reset_ocio():
# Clear OCIO profile if set to Filmic
if os.getenv("OCIO") == get_default_ocio_config():
del os.environ["OCIO"]