Upload extra_config.py
Browse files- extra_config.py +33 -0
extra_config.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import yaml
|
| 3 |
+
import folder_paths
|
| 4 |
+
import logging
|
| 5 |
+
|
| 6 |
+
def load_extra_path_config(yaml_path):
|
| 7 |
+
with open(yaml_path, 'r') as stream:
|
| 8 |
+
config = yaml.safe_load(stream)
|
| 9 |
+
yaml_dir = os.path.dirname(os.path.abspath(yaml_path))
|
| 10 |
+
for c in config:
|
| 11 |
+
conf = config[c]
|
| 12 |
+
if conf is None:
|
| 13 |
+
continue
|
| 14 |
+
base_path = None
|
| 15 |
+
if "base_path" in conf:
|
| 16 |
+
base_path = conf.pop("base_path")
|
| 17 |
+
base_path = os.path.expandvars(os.path.expanduser(base_path))
|
| 18 |
+
if not os.path.isabs(base_path):
|
| 19 |
+
base_path = os.path.abspath(os.path.join(yaml_dir, base_path))
|
| 20 |
+
is_default = False
|
| 21 |
+
if "is_default" in conf:
|
| 22 |
+
is_default = conf.pop("is_default")
|
| 23 |
+
for x in conf:
|
| 24 |
+
for y in conf[x].split("\n"):
|
| 25 |
+
if len(y) == 0:
|
| 26 |
+
continue
|
| 27 |
+
full_path = y
|
| 28 |
+
if base_path:
|
| 29 |
+
full_path = os.path.join(base_path, full_path)
|
| 30 |
+
elif not os.path.isabs(full_path):
|
| 31 |
+
full_path = os.path.abspath(os.path.join(yaml_dir, y))
|
| 32 |
+
logging.info("Adding extra search path {} {}".format(x, full_path))
|
| 33 |
+
folder_paths.add_model_folder_path(x, full_path, is_default)
|