From cb7df7862d900080c0f6db597e2c2bf05185423b Mon Sep 17 00:00:00 2001 From: chrys Date: Mon, 4 Feb 2019 21:21:10 +0100 Subject: [PATCH] add some more bits --- .../vmenu-profiles/KEY/mc/file/open.py | 2 +- .../vmenu-profiles/KEY/mc/file/save.py | 2 +- .../vmenu-profiles/KEY/mc/search/replace.py | 2 +- .../vmenu-profiles/KEY/mc/search/search.py | 2 +- .../vmenu-profiles/KEY/mutt/file/open.py | 2 +- .../vmenu-profiles/KEY/mutt/file/save.py | 2 +- .../vmenu-profiles/KEY/mutt/search/replace.py | 2 +- .../vmenu-profiles/KEY/mutt/search/search.py | 2 +- .../vmenu-profiles/KEY/nano/file/open.py | 2 +- .../vmenu-profiles/KEY/nano/file/save.py | 2 +- .../vmenu-profiles/KEY/nano/search/replace.py | 2 +- .../vmenu-profiles/KEY/nano/search/search.py | 2 +- .../vmenu-profiles/KEY/vim/file/open.py | 2 +- .../vmenu-profiles/KEY/vim/file/save.py | 2 +- .../vmenu-profiles/KEY/vim/search/replace.py | 2 +- .../vmenu-profiles/KEY/vim/search/search.py | 2 +- src/fenrirscreenreader/core/commandManager.py | 49 +++++++++++++++---- src/fenrirscreenreader/core/vmenuManager.py | 22 +++++---- 18 files changed, 69 insertions(+), 34 deletions(-) diff --git a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mc/file/open.py b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mc/file/open.py index f1101b9f..63f33aa6 100644 --- a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mc/file/open.py +++ b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mc/file/open.py @@ -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 diff --git a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mc/file/save.py b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mc/file/save.py index f1101b9f..33c5f261 100644 --- a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mc/file/save.py +++ b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mc/file/save.py @@ -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 diff --git a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mc/search/replace.py b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mc/search/replace.py index f1101b9f..57f2f910 100644 --- a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mc/search/replace.py +++ b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mc/search/replace.py @@ -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 diff --git a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mc/search/search.py b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mc/search/search.py index f1101b9f..d4e2d8c7 100644 --- a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mc/search/search.py +++ b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mc/search/search.py @@ -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 diff --git a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mutt/file/open.py b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mutt/file/open.py index f1101b9f..63f33aa6 100644 --- a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mutt/file/open.py +++ b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mutt/file/open.py @@ -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 diff --git a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mutt/file/save.py b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mutt/file/save.py index f1101b9f..33c5f261 100644 --- a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mutt/file/save.py +++ b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mutt/file/save.py @@ -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 diff --git a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mutt/search/replace.py b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mutt/search/replace.py index f1101b9f..57f2f910 100644 --- a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mutt/search/replace.py +++ b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mutt/search/replace.py @@ -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 diff --git a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mutt/search/search.py b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mutt/search/search.py index f1101b9f..d4e2d8c7 100644 --- a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mutt/search/search.py +++ b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/mutt/search/search.py @@ -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 diff --git a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/nano/file/open.py b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/nano/file/open.py index f1101b9f..63f33aa6 100644 --- a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/nano/file/open.py +++ b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/nano/file/open.py @@ -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 diff --git a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/nano/file/save.py b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/nano/file/save.py index f1101b9f..33c5f261 100644 --- a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/nano/file/save.py +++ b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/nano/file/save.py @@ -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 diff --git a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/nano/search/replace.py b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/nano/search/replace.py index f1101b9f..57f2f910 100644 --- a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/nano/search/replace.py +++ b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/nano/search/replace.py @@ -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 diff --git a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/nano/search/search.py b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/nano/search/search.py index f1101b9f..d4e2d8c7 100644 --- a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/nano/search/search.py +++ b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/nano/search/search.py @@ -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 diff --git a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/vim/file/open.py b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/vim/file/open.py index f1101b9f..63f33aa6 100644 --- a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/vim/file/open.py +++ b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/vim/file/open.py @@ -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 diff --git a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/vim/file/save.py b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/vim/file/save.py index f1101b9f..33c5f261 100644 --- a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/vim/file/save.py +++ b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/vim/file/save.py @@ -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 diff --git a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/vim/search/replace.py b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/vim/search/replace.py index f1101b9f..57f2f910 100644 --- a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/vim/search/replace.py +++ b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/vim/search/replace.py @@ -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 diff --git a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/vim/search/search.py b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/vim/search/search.py index f1101b9f..d4e2d8c7 100644 --- a/src/fenrirscreenreader/commands/vmenu-profiles/KEY/vim/search/search.py +++ b/src/fenrirscreenreader/commands/vmenu-profiles/KEY/vim/search/search.py @@ -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 diff --git a/src/fenrirscreenreader/core/commandManager.py b/src/fenrirscreenreader/core/commandManager.py index 3b316705..b754534d 100644 --- a/src/fenrirscreenreader/core/commandManager.py +++ b/src/fenrirscreenreader/core/commandManager.py @@ -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 diff --git a/src/fenrirscreenreader/core/vmenuManager.py b/src/fenrirscreenreader/core/vmenuManager.py index a2291fde..c59b252c 100755 --- a/src/fenrirscreenreader/core/vmenuManager.py +++ b/src/fenrirscreenreader/core/vmenuManager.py @@ -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