monolith/legacy/utils/loaders/single_loader.py

28 lines
929 B
Python
Raw Normal View History

import sys
2022-07-21 12:40:09 +00:00
from importlib import reload
from os import listdir
from main import CommandMap
2022-07-21 12:40:09 +00:00
from utils.logging.debug import debug
2022-07-21 12:39:41 +00:00
def loadSingle(commandName):
2022-07-21 12:39:41 +00:00
if commandName + ".py" in listdir("commands"):
className = commandName.capitalize() + "Command"
try:
if commandName in CommandMap.keys():
2022-07-21 12:39:41 +00:00
reload(sys.modules["commands." + commandName])
2022-09-05 06:20:30 +00:00
CommandMap[commandName] = getattr(
sys.modules["commands." + commandName], className
)
debug("Reloaded command: %s" % commandName)
return "RELOAD"
2022-07-21 12:39:41 +00:00
module = __import__("commands.%s" % commandName)
CommandMap[commandName] = getattr(getattr(module, commandName), className)
debug("Registered command: %s" % commandName)
return True
except Exception as err:
return err
return False