43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
from typing import Dict, List
|
|
|
|
class ClsRegister:
|
|
clsLst:Dict[str,Dict[str,str]] = {}
|
|
|
|
@classmethod
|
|
def add(cls,catalog,name,obj) -> None:
|
|
if catalog in cls.clsLst:
|
|
registry = cls.clsLst[catalog]
|
|
registry[name] = obj
|
|
else:
|
|
registry:Dict[str,str] = {}
|
|
registry[name] = obj
|
|
cls.clsLst[catalog] = registry
|
|
|
|
@classmethod
|
|
def get(cls,catalog,name,fuzzy:bool=False) -> None:
|
|
if catalog in cls.clsLst:
|
|
registry = cls.clsLst[catalog]
|
|
for key,value in registry.items():
|
|
if fuzzy:
|
|
if key in name:
|
|
return value
|
|
else:
|
|
if key == name:
|
|
return value
|
|
return None
|
|
|
|
@classmethod
|
|
def getClsList(cls,catalog) -> None:
|
|
res_Lst = []
|
|
if catalog in cls.clsLst:
|
|
registry = cls.clsLst[catalog]
|
|
for key,value in registry.items():
|
|
res_Lst.append(value)
|
|
return res_Lst
|
|
|
|
|
|
def register(catalog,name):
|
|
def decorator(className):
|
|
ClsRegister.add(catalog,name,className)
|
|
return className
|
|
return decorator |