Implement loading new modules at runtime

This commit is contained in:
2018-02-23 23:26:21 +00:00
parent cb7142ef88
commit 378c4d9bba
5 changed files with 49 additions and 8 deletions

View File

@@ -8,8 +8,8 @@ def loadCommands(func):
if filename.endswith('.py') and filename != "__init__.py":
commandName = filename[0:-3]
className = commandName.capitalize()
#try:
__import__('commands.%s' % commandName)
eval('commands.%s.%s(func)' % (commandName, className))
#except Exception as err:
# error("Exception while loading command %s:\n%s" % (commandName, err))
try:
__import__('commands.%s' % commandName)
eval('commands.%s.%s(func)' % (commandName, className))
except Exception as err:
error("Exception while loading command %s:\n%s" % (commandName, err))

View File

@@ -0,0 +1,17 @@
from os import listdir
from core.main import *
from utils.logging.log import *
import commands
def loadSingle(command, func):
if command+".py" in listdir("commands"):
try:
if command in CommandMap.keys():
return "Cannot reload modules"
else:
className = command.capitalize()
__import__("commands.%s" % command)
eval("commands.%s.%s(func)" % (command, className))
return True
except Exception as err:
return err