-
Notifications
You must be signed in to change notification settings - Fork 37
/
config.py
68 lines (46 loc) · 1.56 KB
/
config.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
import os
import json
import inspect
from typing import Dict
from server import PromptServer
from .modules.logger import logger
comfy_dir = os.path.dirname(inspect.getfile(PromptServer))
ext_dir = os.path.dirname(os.path.realpath(__file__))
config_path = os.path.join(ext_dir, "config.json")
def __get_dir(root: str, subpath=None, mkdir=False):
dir = root
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_ext_dir(subpath=None, mkdir=False):
return __get_dir(ext_dir, subpath, mkdir)
def get_comfy_dir(subpath=None, mkdir=False):
return __get_dir(comfy_dir, subpath, mkdir)
def write_config(config):
with open(config_path, "w") as f:
json.dump(config, f, indent=4)
def load_config() -> Dict:
default_config = {
"av_endpoint": "https://api.artventure.ai",
"av_token": "",
"runner_enabled": False,
"remove_runner_images_after_upload": False,
}
if not os.path.isfile(config_path):
logger.info("Config file not found, creating...")
write_config(default_config)
with open(config_path, "r") as f:
config = json.load(f)
need_update = False
for key, value in default_config.items():
if key not in config:
config[key] = value
need_update = True
if need_update:
write_config(config)
logger.debug(f"Loaded config {config}")
return config
config = load_config()