add some more bits

This commit is contained in:
chrys 2019-02-04 21:21:10 +01:00
parent af8bf385a7
commit cb7df7862d
18 changed files with 69 additions and 34 deletions

View File

@ -16,6 +16,6 @@ class command():
def getDescription(self):
return 'No description found'
def run(self):
pass
self.env['runtime']['outputManager'].presentText('ok i run open macro' , interrupt=True)
def setCallback(self, callback):
pass

View File

@ -16,6 +16,6 @@ class command():
def getDescription(self):
return 'No description found'
def run(self):
pass
self.env['runtime']['outputManager'].presentText('ok i run open save' , interrupt=True)
def setCallback(self, callback):
pass

View File

@ -16,6 +16,6 @@ class command():
def getDescription(self):
return 'No description found'
def run(self):
pass
self.env['runtime']['outputManager'].presentText('ok i run replace macro' , interrupt=True)
def setCallback(self, callback):
pass

View File

@ -16,6 +16,6 @@ class command():
def getDescription(self):
return 'No description found'
def run(self):
pass
self.env['runtime']['outputManager'].presentText('ok i run search macro' , interrupt=True)
def setCallback(self, callback):
pass

View File

@ -16,6 +16,6 @@ class command():
def getDescription(self):
return 'No description found'
def run(self):
pass
self.env['runtime']['outputManager'].presentText('ok i run open macro' , interrupt=True)
def setCallback(self, callback):
pass

View File

@ -16,6 +16,6 @@ class command():
def getDescription(self):
return 'No description found'
def run(self):
pass
self.env['runtime']['outputManager'].presentText('ok i run open save' , interrupt=True)
def setCallback(self, callback):
pass

View File

@ -16,6 +16,6 @@ class command():
def getDescription(self):
return 'No description found'
def run(self):
pass
self.env['runtime']['outputManager'].presentText('ok i run replace macro' , interrupt=True)
def setCallback(self, callback):
pass

View File

@ -16,6 +16,6 @@ class command():
def getDescription(self):
return 'No description found'
def run(self):
pass
self.env['runtime']['outputManager'].presentText('ok i run search macro' , interrupt=True)
def setCallback(self, callback):
pass

View File

@ -16,6 +16,6 @@ class command():
def getDescription(self):
return 'No description found'
def run(self):
pass
self.env['runtime']['outputManager'].presentText('ok i run open macro' , interrupt=True)
def setCallback(self, callback):
pass

View File

@ -16,6 +16,6 @@ class command():
def getDescription(self):
return 'No description found'
def run(self):
pass
self.env['runtime']['outputManager'].presentText('ok i run open save' , interrupt=True)
def setCallback(self, callback):
pass

View File

@ -16,6 +16,6 @@ class command():
def getDescription(self):
return 'No description found'
def run(self):
pass
self.env['runtime']['outputManager'].presentText('ok i run replace macro' , interrupt=True)
def setCallback(self, callback):
pass

View File

@ -16,6 +16,6 @@ class command():
def getDescription(self):
return 'No description found'
def run(self):
pass
self.env['runtime']['outputManager'].presentText('ok i run search macro' , interrupt=True)
def setCallback(self, callback):
pass

View File

@ -16,6 +16,6 @@ class command():
def getDescription(self):
return 'No description found'
def run(self):
pass
self.env['runtime']['outputManager'].presentText('ok i run open macro' , interrupt=True)
def setCallback(self, callback):
pass

View File

@ -16,6 +16,6 @@ class command():
def getDescription(self):
return 'No description found'
def run(self):
pass
self.env['runtime']['outputManager'].presentText('ok i run open save' , interrupt=True)
def setCallback(self, callback):
pass

View File

@ -16,6 +16,6 @@ class command():
def getDescription(self):
return 'No description found'
def run(self):
pass
self.env['runtime']['outputManager'].presentText('ok i run replace macro' , interrupt=True)
def setCallback(self, callback):
pass

View File

@ -16,6 +16,6 @@ class command():
def getDescription(self):
return 'No description found'
def run(self):
pass
self.env['runtime']['outputManager'].presentText('ok i run search macro' , interrupt=True)
def setCallback(self, callback):
pass

View File

@ -31,22 +31,53 @@ class commandManager():
def shutdown(self):
for commandFolder in self.env['general']['commandFolderList']:
self.env['runtime']['commandManager'].shutdownCommands(commandFolder)
def loadFile(self, filepath = ''):
if filepath == '':
return None
if not os.path.exists(filepath):
self.env['runtime']['debug'].writeDebugOut("loadFile: filepath not exists:" + filepath ,debug.debugLevel.WARNING)
print('1')
return None
if os.path.isdir(filepath):
print('2')
self.env['runtime']['debug'].writeDebugOut("loadFile: filepath is a directory:" + filepath ,debug.debugLevel.ERROR)
return None
if not os.access(filepath, os.R_OK):
print('3')
self.env['runtime']['debug'].writeDebugOut("loadFile: filepath not readable:" + filepath ,debug.debugLevel.ERROR)
return None
try:
fileName, fileExtension = os.path.splitext(filepath)
fileName = fileName.split('/')[-1]
if fileName.startswith('__'):
return None
if fileExtension.lower() == '.py':
command_mod = module_utils.importModule(fileName, filepath)
command = command_mod.command()
command.initialize(self.env)
self.env['runtime']['debug'].writeDebugOut("loadFile: Load command:" + filepath ,debug.debugLevel.INFO, onAnyLevel=True)
return command
except Exception as e:
self.env['runtime']['debug'].writeDebugOut("loadFile: Loading command:" + filepath ,debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
return None
def loadCommands(self, section='commands',commandPath=''):
if commandPath =='':
commandPath = fenrirPath+ "/commands/"
if not commandPath.endswith('/'):
commandPath += '/'
commandPath += '/'
commandFolder = commandPath + section +"/"
if not os.path.exists(commandFolder):
self.env['runtime']['debug'].writeDebugOut("commandFolder not exists:" + commandFolder ,debug.debugLevel.WARNING)
self.env['runtime']['debug'].writeDebugOut("loadCommands: commandFolder not exists:" + commandFolder ,debug.debugLevel.WARNING)
return
if not os.path.isdir(commandFolder):
self.env['runtime']['debug'].writeDebugOut("commandFolder not a directory:" + commandFolder ,debug.debugLevel.ERROR)
return
self.env['runtime']['debug'].writeDebugOut("loadCommands: commandFolder not a directory:" + commandFolder ,debug.debugLevel.ERROR)
return
if not os.access(commandFolder, os.R_OK):
self.env['runtime']['debug'].writeDebugOut("commandFolder not readable:" + commandFolder ,debug.debugLevel.ERROR)
return
self.env['runtime']['debug'].writeDebugOut("loadCommands: commandFolder not readable:" + commandFolder ,debug.debugLevel.ERROR)
return
self.env['commands'][section] = {}
self.env['commandsIgnore'][section] = {}
commandList = glob.glob(commandFolder+'*')
@ -66,9 +97,9 @@ class commandManager():
self.env['commands'][section][fileName.upper()] = command_mod.command()
self.env['commandsIgnore'][section][fileName.upper()[fileName.upper().find('-')+1:]+'_IGNORE'] = False
self.env['commands'][section][fileName.upper()].initialize(self.env)
self.env['runtime']['debug'].writeDebugOut("Load command:" + section + "." + fileName.upper() ,debug.debugLevel.INFO, onAnyLevel=True)
self.env['runtime']['debug'].writeDebugOut("loadCommands: Load command:" + section + "." + fileName.upper() ,debug.debugLevel.INFO, onAnyLevel=True)
except Exception as e:
self.env['runtime']['debug'].writeDebugOut("Loading command:" + command ,debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut("loadCommands: Loading command:" + command ,debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
continue

View File

@ -79,7 +79,9 @@ class vmenuManager():
if self.currIndex == None:
return
try:
pass
command = self.getValueByPath(self.menuDict, self.currIndex)
if not command == None:
command.run()
except:
self.incLevel()
def incLevel(self):
@ -87,10 +89,9 @@ class vmenuManager():
return
try:
r = self.getValueByPath(self.menuDict, self.currIndex +[0])
if not r:
return
if not isinstance(r, dict):
return
print(r)
#if not r:
# return
if r == {}:
return
except:
@ -128,15 +129,18 @@ class vmenuManager():
def fs_tree_to_dict(self, path_):
for root, dirs, files in os.walk(path_):
tree = {d: self.fs_tree_to_dict(os.path.join(root, d)) for d in dirs}
tree.update({f: root + '/' + f for f in files})
for f in files:
try:
command = self.env['runtime']['commandManager'].loadFile(root + '/' + f)
tree.update({f: command})
except Exception as e:
print(e)
return tree # note we discontinue iteration trough os.walk
def getNestedByPath(self, complete, path):
path = path.copy()
if path != []:
index = list(complete.keys())[path[0]]
print(path)
path.remove(0)
nested = self.getNestedByPath(complete[index], path)
nested = self.getNestedByPath(complete[index], path[1:])
return nested
else:
return complete