load scripts

This commit is contained in:
chrys 2016-10-18 20:08:16 +02:00
parent 33fa525497
commit c99c45436e
2 changed files with 25 additions and 1 deletions

View File

@ -6,6 +6,7 @@
from core import debug
import subprocess, os
from subprocess import Popen, PIPE
class command():
def __init__(self):
@ -30,6 +31,8 @@ class command():
p = Popen(self.scriptPath , stdout=PIPE, stderr=PIPE, shell=True)
stdout, stderr = p.communicate()
self.env['runtime']['outputManager'].interruptOutput()
stderr = str(stderr)
stdout = str(stdout)
if stderr != '':
self.env['runtime']['outputManager'].presentText(stdout , soundIcon='', interrupt=False)
if stdout != '':

View File

@ -64,18 +64,39 @@ class commandManager():
self.env['runtime']['debug'].writeDebugOut("scriptpath not readable:" + scriptPath ,debug.debugLevel.ERROR)
return
commandList = glob.glob(self.env['runtime']['settingsManager'].getSetting('general', 'scriptPath')+'/*')
subCommand = os.path.dirname(os.path.realpath(__main__.__file__)) + '/commands/commands/subprocess.py'
for command in commandList:
try:
fileName, fileExtension = os.path.splitext(command)
fileName = fileName.split('/')[-1]
if fileName.startswith('__'):
continue
spec = importlib.util.spec_from_file_location(__main__.__file__+'/commands/commands/subprocess.py', command)
spec = importlib.util.spec_from_file_location(fileName ,subCommand)
command_mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(command_mod)
self.env['commands'][section][fileName.upper()] = command_mod.command()
self.env['commands'][section][fileName.upper()].initialize(self.env,command)
self.env['commands'][section][fileName.upper()].run()
self.env['runtime']['debug'].writeDebugOut("Load script:" + section + "." + fileName.upper() ,debug.debugLevel.INFO, onAnyLevel=True)
commSettings = fileName.upper().split('__-__')
if len(commSettings) == 1:
keys = commSettings[0]
elif len(commSettings) == 2:
keys = commSettings[1]
elif len(commSettings) > 2:
continue
keys = keys.split('__+__')
shortcutKeys = []
shortcut = []
for key in keys:
shortcutKeys.append(key.upper())
if not 'KEY_SCRIPT' in shortcutKeys:
shortcutKeys.append('KEY_SCRIPT')
shortcut.append(1)
shortcut.append(sorted(shortcutKeys))
print(shortcut,command)
self.env['bindings'][str(shortcut)] = fileName.upper()
except Exception as e:
print(e)
self.env['runtime']['debug'].writeDebugOut("Loading script:" + command ,debug.debugLevel.ERROR)