Moved files to subdirectory
This commit is contained in:
25
legacy/utils/loaders/command_loader.py
Normal file
25
legacy/utils/loaders/command_loader.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from os import listdir
|
||||
|
||||
from main import CommandMap
|
||||
from utils.logging.debug import debug
|
||||
from utils.logging.log import error
|
||||
|
||||
|
||||
def loadCommands(allowDup=False):
|
||||
for filename in listdir("commands"):
|
||||
if filename.endswith(".py") and filename != "__init__.py":
|
||||
commandName = filename[0:-3]
|
||||
className = commandName.capitalize() + "Command"
|
||||
# try:
|
||||
module = __import__("commands.%s" % commandName)
|
||||
if commandName not in CommandMap:
|
||||
CommandMap[commandName] = getattr(getattr(module, commandName), className)
|
||||
debug("Registered command: %s" % commandName)
|
||||
else:
|
||||
if allowDup:
|
||||
CommandMap[commandName] = getattr(getattr(module, commandName), className)
|
||||
debug("Registered command: %s" % commandName)
|
||||
|
||||
error("Duplicate command: %s" % (commandName))
|
||||
# except Exception as err:
|
||||
# error("Exception while loading command %s:\n%s" % (commandName, err))
|
||||
Reference in New Issue
Block a user