forked from AIGODLIKE/ComfyUI-BlenderAI-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datas.py
59 lines (45 loc) · 1.4 KB
/
datas.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
from pathlib import Path
PRESETS_DIR = Path(__file__).parent / "presets"
GROUPS_DIR = Path(__file__).parent / "groups"
IMG_SUFFIX = {".png", ".jpg", ".jpeg"}
VERSION = ""
def get_bl_version():
if VERSION: return VERSION
from . import bl_info
return ".".join([str(i) for i in bl_info['version']])
VERSION = get_bl_version()
class MetaIn(type):
CACHE: dict[str, dict] = {}
def __contains__(cls, name):
return name in cls.CACHE
def __setitem__(cls, name, value):
if type(value) not in {list, dict}:
return
cls.CACHE[name] = value
def __getitem__(cls, name) -> dict:
return cls.CACHE.setdefault(name, {})
class EnumCache(metaclass=MetaIn):
CACHE: dict[str, dict] = {}
@staticmethod
def reg_cache(name):
EnumCache.CACHE[name] = {}
return EnumCache[name]
@staticmethod
def unreg_cache(name):
EnumCache.CACHE.pop(name)
@staticmethod
def clear(name=None):
if name:
EnumCache[name].clear()
return
for cache in EnumCache.CACHE.values():
cache.clear()
ENUM_ITEMS_CACHE = EnumCache["ENUM_ITEMS_CACHE"]
EnumCache["presets_dir"] = []
EnumCache["groups_dir"] = []
PROP_CACHE = {
"presets": EnumCache.reg_cache("presets"),
"presets_dir": EnumCache["presets_dir"],
"groups": EnumCache.reg_cache("groups"),
"groups_dir": EnumCache["groups_dir"],
}