diff --git a/src/fenrir-package/core/commandManager.py b/src/fenrir-package/core/commandManager.py index 6f7ea251..7bf0e642 100644 --- a/src/fenrir-package/core/commandManager.py +++ b/src/fenrir-package/core/commandManager.py @@ -1,10 +1,30 @@ #!/bin/python +import importlib.util +import glob +import os class commandManager(): def __init__(self): pass def loadCommands(self, environment): + commandFolder = "commands/" + commandList = glob.glob(commandFolder+'*') + for currCommand in commandList: + try: + fileName, fileExtension = os.path.splitext(currCommand) + fileName = fileName.split('/')[-1] + if fileName in ['__init__','__pycache__']: + continue + print(fileName) + if fileExtension.lower() == 'py': + spec = importlib.util.spec_from_file_location(fileName, currCommand) + command_mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(command_mod) + environment['commands']['fileName'] = command_mod() + except: + continue return environment + def executeCommand(self, environment): print(environment['commandInfo']['currCommand']) if self.isCommandDefined(environment): diff --git a/src/fenrir-package/core/inputManager.py b/src/fenrir-package/core/inputManager.py index 2a803842..ec55db4e 100644 --- a/src/fenrir-package/core/inputManager.py +++ b/src/fenrir-package/core/inputManager.py @@ -8,7 +8,7 @@ class inputManager(): def __init__(self): self.devices = map(evdev.InputDevice, (evdev.list_devices())) self.devices = {dev.fd: dev for dev in self.devices} - for dev in self.devices.values(): print(dev) + #for dev in self.devices.values(): print(dev) def getKeyPressed(self, environment): r, w, x = select(self.devices, [], []) diff --git a/src/fenrir-package/fenrir.py b/src/fenrir-package/fenrir.py index 3e1317c8..95e6fe27 100755 --- a/src/fenrir-package/fenrir.py +++ b/src/fenrir-package/fenrir.py @@ -27,6 +27,7 @@ class fenrir(): self.environment = environment.environment self.environment['runtime']['inputManager'] = inputManager.inputManager() self.environment['runtime']['commandManager'] = commandManager.commandManager() + self.environment = self.environment['runtime']['commandManager'].loadCommands(self.environment) self.environment['runtime']['debug'] = debug.debug() signal.signal(signal.SIGINT, self.captureSignal)