def __init__(self, configpath):
self.configpath = configpath
# Find libraries inside the lib directory
dir_path = os.path.join(os.path.dirname(__file__), "libraries")
lib_files = [f for f in os.listdir(dir_path) if
os.path.isfile(os.path.join(dir_path, f)) and
f.lower().endswith(".py")
]
self.responses = []
self.libraries = []
for f in lib_files:
# Try to load the module
try:
module_name = "hal.libraries." + f[:-3]
module = importlib.import_module(module_name)
for name, obj in inspect.getmembers(module):
# Find classes that inherit from HalLibrary
if inspect.isclass(obj) and issubclass(obj, HalLibrary) and \
name != "HalLibrary" and not inspect.isabstract(obj):
self.libraries.append(obj)
except:
self.add_response("Error loading library {}".format(f))
raise
评论列表
文章目录