Prepare command loader for reloading commands

This commit is contained in:
Mark Veidemanis 2020-11-01 03:38:47 +00:00
parent f7e1f2d221
commit abdfc48b95
1 changed files with 5 additions and 1 deletions

View File

@ -6,7 +6,7 @@ import commands
from main import CommandMap
def loadCommands():
def loadCommands(allowDup=False):
for filename in listdir("commands"):
if filename.endswith(".py") and filename != "__init__.py":
commandName = filename[0:-3]
@ -17,6 +17,10 @@ def loadCommands():
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))