Repository navigation
Expand file tree
/
Copy pathutils.py
More file actions
62 lines (47 loc) · 1.5 KB
/
Copy pathutils.py
File metadata and controls
62 lines (47 loc) · 1.5 KB
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
import json
import os
config = None
def is_logging_enabled():
config = get_extension_config()
if "logging" not in config:
return False
return config["logging"]
def log(message, type=None, module_name=None):
if not is_logging_enabled():
return
if type is not None:
message = f"[{type}] {message}"
if module_name is None:
module_name = "common"
print(f"(runcomfy:{module_name}) {message}")
def get_ext_dir(subpath=None, mkdir=False):
dir = os.path.dirname(__file__)
if subpath is not None:
dir = os.path.join(dir, subpath)
dir = os.path.abspath(dir)
if mkdir and not os.path.exists(dir):
os.makedirs(dir)
return dir
def get_extension_config(reload=False):
global config
if reload == False and config is not None:
return config
config_path = get_ext_dir("runcomfy.config.json")
if not os.path.exists(config_path):
log(f"Failed to load config at {config_path}", type="ERROR")
raise FileNotFoundError(f"Failed to load config at {config_path}")
with open(config_path, "r") as f:
config = json.loads(f.read())
return config
def get_config_value(key, default=None, throw=False):
split = key.split(".")
obj = get_extension_config()
for s in split:
if s in obj:
obj = obj[s]
else:
if throw:
raise KeyError("Configuration key missing: " + key)
else:
return default
return obj