fix some other things

This commit is contained in:
chrys 2016-09-17 01:26:07 +02:00
parent 6569ce004c
commit 02f67b028b

View File

@ -18,21 +18,21 @@ class commandManager():
def loadCommands(self, environment, section='commands'): def loadCommands(self, environment, section='commands'):
commandFolder = "commands/" + section +"/" commandFolder = "commands/" + section +"/"
commandList = glob.glob(commandFolder+'*') commandList = glob.glob(commandFolder+'*')
for currCommand in commandList: for command in commandList:
try: try:
fileName, fileExtension = os.path.splitext(currCommand) fileName, fileExtension = os.path.splitext(command)
fileName = fileName.split('/')[-1] fileName = fileName.split('/')[-1]
if fileName in ['__init__','__pycache__']: if fileName in ['__init__','__pycache__']:
continue continue
if fileExtension.lower() == '.py': if fileExtension.lower() == '.py':
spec = importlib.util.spec_from_file_location(fileName, currCommand) spec = importlib.util.spec_from_file_location(fileName, command)
command_mod = importlib.util.module_from_spec(spec) command_mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(command_mod) spec.loader.exec_module(command_mod)
environment['commands'][section][fileName] = command_mod.command() environment['commands'][section][fileName.upper()] = command_mod.command()
environment['commands'][section][fileName].initialize(environment) environment['commands'][section][fileName.upper()].initialize(environment)
except Exception as e: except Exception as e:
print(e) print(e)
environment['runtime']['debug'].writeDebugOut(environment,"Error while loading command:" + currCommand ,debug.debugLevel.ERROR) environment['runtime']['debug'].writeDebugOut(environment,"Error while loading command:" + command ,debug.debugLevel.ERROR)
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR) environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
continue continue
return environment return environment
@ -40,33 +40,36 @@ class commandManager():
def executeTriggerCommands(self, environment, trigger): def executeTriggerCommands(self, environment, trigger):
if environment['runtime']['screenManager'].isSuspendingScreen(environment): if environment['runtime']['screenManager'].isSuspendingScreen(environment):
return environment return environment
for cmd in sorted(environment['commands'][trigger]): for command in sorted(environment['commands'][trigger]):
if self.commandExists(environment, command, trigger):
try: try:
environment['commands'][trigger][cmd].run(environment) environment['commands'][trigger][command].run(environment)
except Exception as e: except Exception as e:
print(e) print(e)
environment['runtime']['debug'].writeDebugOut(environment,"Error while executing trigger:" + trigger + "." + cmd ,debug.debugLevel.ERROR) environment['runtime']['debug'].writeDebugOut(environment,"Error while executing trigger:" + trigger + "." + cmd ,debug.debugLevel.ERROR)
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR) environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
return environment return environment
def executeCommand(self, environment, currCommand, section = 'commands'): def executeCommand(self, environment, command, section = 'commands'):
if environment['runtime']['screenManager'].isSuspendingScreen(environment) : if environment['runtime']['screenManager'].isSuspendingScreen(environment) :
return environment return environment
if self.isCommandDefined(environment): if self.commandExists(environment, command, section):
try: try:
environment['commands'][section][currCommand].run(environment) environment['commands'][section][command].run(environment)
except Exception as e: except Exception as e:
print(e) print(e)
environment['runtime']['debug'].writeDebugOut(environment,"Error while executing command:" + section + "." + currCommand ,debug.debugLevel.ERROR) environment['runtime']['debug'].writeDebugOut(environment,"Error while executing command:" + section + "." + command ,debug.debugLevel.ERROR)
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR) environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
environment['commandInfo']['currCommand'] = '' environment['commandInfo']['currCommand'] = ''
environment['commandInfo']['lastCommandExecutionTime'] = time.time() environment['commandInfo']['lastCommandExecutionTime'] = time.time()
return environment return environment
def isShortcutDefined(self, environment, shortcut): def isCommandQueued(self, environment):
return( str(shortcut).upper() in environment['bindings']) return environment['commandInfo']['currCommand'] != ''
def setCurrCommandForExec(self, environment, currCommand): def queueCommand(self, environment, command):
environment['commandInfo']['currCommand'] = currCommand environment['commandInfo']['currCommand'] = command
return environment return environment
def commandExists(self, environment, command, section = 'commands'):
return( command.upper() in environment['commands'][section])