32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
|
import sys
|
||
|
import os
|
||
|
import importlib
|
||
|
import inspect
|
||
|
|
||
|
DEBUG = False
|
||
|
|
||
|
# relative imports suck - https://gideonbrimleaf.github.io/2021/01/26/relative-imports-python.html
|
||
|
path = os.path.realpath(__file__)
|
||
|
path = path[:path.rfind('/')]
|
||
|
sys.path.insert(1, f'{path}/extensions/checkers')
|
||
|
|
||
|
# importlib used to import stuff programmatically, rather than using the hardcoded import keyword, basically the same but it seems it can't import *just* a class
|
||
|
uptime_extension_imports = []
|
||
|
for ext_name in os.listdir(f'{path}/extensions/checkers'):
|
||
|
if ext_name[0] != '.':
|
||
|
uptime_extension_imports.append(f'{ext_name}.{ext_name}')
|
||
|
|
||
|
# uptime_checkers contains all the classes for the checker extensions
|
||
|
# e.g. {'CheckerTemplate': checker_template.checker_template.CheckerTemplate}
|
||
|
checkers = dict()
|
||
|
for ext in [importlib.import_module(ext) for ext in uptime_extension_imports]:
|
||
|
for name, obj in inspect.getmembers(ext):
|
||
|
if inspect.isclass(obj):
|
||
|
checkers[name] = obj
|
||
|
|
||
|
if DEBUG:
|
||
|
print('uptime_extension_imports:', uptime_extension_imports)
|
||
|
print('checkers:', checkers)
|
||
|
|
||
|
print(checkers['CheckerTemplate'].get_status())
|