add custom command path

This commit is contained in:
chrys87 2017-02-23 15:18:29 +01:00 committed by GitHub
parent acb91f7b91
commit c904821b57

View File

@ -15,11 +15,23 @@ class commandManager():
def initialize(self, environment): def initialize(self, environment):
self.env = environment self.env = environment
self.env['runtime']['commandManager'].loadCommands('commands') self.env['runtime']['commandManager'].loadCommands('commands')
self.env['runtime']['commandManager'].loadCommands('commands',
self.env['runtime']['settingsManager'].getSetting('general', 'commandPath'))
self.env['runtime']['commandManager'].loadCommands('onInput') self.env['runtime']['commandManager'].loadCommands('onInput')
self.env['runtime']['commandManager'].loadCommands('onInput',
self.env['runtime']['settingsManager'].getSetting('general', 'commandPath'))
self.env['runtime']['commandManager'].loadCommands('onScreenUpdate') self.env['runtime']['commandManager'].loadCommands('onScreenUpdate')
self.env['runtime']['commandManager'].loadCommands('onScreenUpdate',
self.env['runtime']['settingsManager'].getSetting('general', 'commandPath'))
self.env['runtime']['commandManager'].loadCommands('onScreenChanged') self.env['runtime']['commandManager'].loadCommands('onScreenChanged')
self.env['runtime']['commandManager'].loadCommands('onScreenChanged',
self.env['runtime']['settingsManager'].getSetting('general', 'commandPath'))
self.env['runtime']['commandManager'].loadCommands('onApplicationChange') self.env['runtime']['commandManager'].loadCommands('onApplicationChange')
self.env['runtime']['commandManager'].loadCommands('onApplicationChange',
self.env['runtime']['settingsManager'].getSetting('general', 'commandPath'))
self.env['runtime']['commandManager'].loadCommands('onSwitchApplicationProfile') self.env['runtime']['commandManager'].loadCommands('onSwitchApplicationProfile')
self.env['runtime']['commandManager'].loadCommands('onSwitchApplicationProfile',
self.env['runtime']['settingsManager'].getSetting('general', 'commandPath'))
self.env['runtime']['commandManager'].loadScriptCommands() self.env['runtime']['commandManager'].loadScriptCommands()
def shutdown(self): def shutdown(self):
self.env['runtime']['commandManager'].shutdownCommands('commands') self.env['runtime']['commandManager'].shutdownCommands('commands')
@ -29,8 +41,12 @@ class commandManager():
self.env['runtime']['commandManager'].shutdownCommands('onApplicationChange') self.env['runtime']['commandManager'].shutdownCommands('onApplicationChange')
self.env['runtime']['commandManager'].shutdownCommands('onSwitchApplicationProfile') self.env['runtime']['commandManager'].shutdownCommands('onSwitchApplicationProfile')
def loadCommands(self, section='commands'): def loadCommands(self, section='commands',commandPath=''):
commandFolder = os.path.dirname(os.path.realpath(__main__.__file__)) + "/commands/" + section +"/" if commandPath =='':
commandPath = os.path.dirname(os.path.realpath(__main__.__file__))
if not commandPath.endswith('/'):
commandPath += '/'
commandFolder = commandPath + "/commands/" + section +"/"
commandList = glob.glob(commandFolder+'*') commandList = glob.glob(commandFolder+'*')
for command in commandList: for command in commandList:
try: try:
@ -50,8 +66,9 @@ class commandManager():
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
continue continue
def loadScriptCommands(self, section='commands'): def loadScriptCommands(self, section='commands', scriptPath=''):
scriptPath = self.env['runtime']['settingsManager'].getSetting('general', 'scriptPath') if scriptPath =='':
scriptPath = self.env['runtime']['settingsManager'].getSetting('general', 'scriptPath')
if not scriptPath.endswith('/'): if not scriptPath.endswith('/'):
scriptPath += '/' scriptPath += '/'
if not os.path.exists(scriptPath) or scriptPath == '/': if not os.path.exists(scriptPath) or scriptPath == '/':