implement plugin autoload

This commit is contained in:
chrys 2016-07-09 02:48:22 +02:00
parent 5478900288
commit 70ba9a7a66
3 changed files with 22 additions and 1 deletions

View File

@ -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):

View File

@ -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, [], [])

View File

@ -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)