From 876be9a6d3488cb0c09f2e74123a5a30d435b181 Mon Sep 17 00:00:00 2001 From: chrys Date: Wed, 12 Oct 2016 23:14:58 +0200 Subject: [PATCH] improve debug --- src/fenrir/core/commandManager.py | 5 ++--- src/fenrir/core/debug.py | 13 +++++++++---- src/fenrir/core/settingsManager.py | 13 +++++++------ 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/fenrir/core/commandManager.py b/src/fenrir/core/commandManager.py index 1822066a..36d8d97f 100644 --- a/src/fenrir/core/commandManager.py +++ b/src/fenrir/core/commandManager.py @@ -34,10 +34,9 @@ class commandManager(): commandList = glob.glob(commandFolder+'*') for command in commandList: try: - print(command) fileName, fileExtension = os.path.splitext(command) fileName = fileName.split('/')[-1] - if fileName in ['__init__','__pycache__']: + if fileName.startswith('__'): continue if fileExtension.lower() == '.py': spec = importlib.util.spec_from_file_location(fileName, command) @@ -46,7 +45,7 @@ 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) + self.env['runtime']['debug'].writeDebugOut("Load command:" + section + "." + fileName.upper() ,debug.debugLevel.INFO, onAnyLevel=True) except Exception as e: print(e) self.env['runtime']['debug'].writeDebugOut("Loading command:" + command ,debug.debugLevel.ERROR) diff --git a/src/fenrir/core/debug.py b/src/fenrir/core/debug.py index 9b64b035..0935af91 100644 --- a/src/fenrir/core/debug.py +++ b/src/fenrir/core/debug.py @@ -37,16 +37,21 @@ class debug(): self._file = open(self._fileName,'a') self._fileOpened = True - def writeDebugOut(self, text, level = debugLevel.DEACTIVE): - if self.env['runtime']['settingsManager'].getSettingAsInt('general','debugLevel') < int(level): + def writeDebugOut(self, text, level = debugLevel.DEACTIVE, onAnyLevel=False): + if (self.env['runtime']['settingsManager'].getSettingAsInt('general','debugLevel') < int(level)) or \ + not (onAnyLevel and self.env['runtime']['settingsManager'].getSettingAsInt('general','debugLevel') > int(debugLevel.DEACTIVE)) : if self._fileOpened: self.closeDebugFile() return else: if not self._fileOpened: self.openDebugFile() - msg = str(level) +' ' + str(datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f') -) + ': ' + text + if onAnyLevel: + msg = 'INFO ' + str(datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')) + else: + msg = str(level) +' ' + str(datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f') +) + msg += ': ' + text print(msg) self._file.write(msg + '\n') diff --git a/src/fenrir/core/settingsManager.py b/src/fenrir/core/settingsManager.py index 0d1ad1d9..ec345864 100644 --- a/src/fenrir/core/settingsManager.py +++ b/src/fenrir/core/settingsManager.py @@ -55,7 +55,7 @@ class settingsManager(): shortcutKeys.append(key.upper()) shortcut.append(shortcutRepeat) shortcut.append(sorted(shortcutKeys)) - self.env['runtime']['debug'].writeDebugOut("Shortcut: "+ str(shortcut) + ' command:' +commandName ,debug.debugLevel.INFO) + self.env['runtime']['debug'].writeDebugOut("Shortcut: "+ str(shortcut) + ' command:' +commandName ,debug.debugLevel.INFO, onAnyLevel=True) self.env['bindings'][str(shortcut)] = commandName kbConfig.close() @@ -85,6 +85,7 @@ class settingsManager(): if os.path.exists(soundIconPath + Values[1]): soundIconFile = soundIconPath + Values[1] self.env['soundIcons'][soundIcon] = soundIconFile + self.env['runtime']['debug'].writeDebugOut("SoundIcon: " + soundIcon + '.' + soundIconFile, debug.debugLevel.INFO, onAnyLevel=True) siConfig.close() def loadDicts(self, dictConfigPath=os.path.dirname(os.path.realpath(__main__.__file__)) + '/../../config/punctuation/default.conf'): @@ -115,7 +116,7 @@ class settingsManager(): elif len(sepLine) > 2: sepLine[1] = ':===:' self.env['punctuation'][currDictName][sepLine[0]] = sepLine[1] - self.env['runtime']['debug'].writeDebugOut("Punctuation: " + currDictName + '.' + str(sepLine[0]) + ' :' + sepLine[1] ,debug.debugLevel.INFO) + self.env['runtime']['debug'].writeDebugOut("Punctuation: " + currDictName + '.' + str(sepLine[0]) + ' :' + sepLine[1] ,debug.debugLevel.INFO, onAnyLevel=True) dictConfig.close() def loadSettings(self, settingConfigPath): @@ -251,10 +252,10 @@ class settingsManager(): environment['runtime']['screenManager'] = screenManager.screenManager() environment['runtime']['screenManager'].initialize(environment) - environment['runtime']['debug'].writeDebugOut('\/-------environment-------\/',debug.debugLevel.ERROR) - environment['runtime']['debug'].writeDebugOut(str(environment),debug.debugLevel.ERROR) - environment['runtime']['debug'].writeDebugOut('\/-------settings.conf-------\/',debug.debugLevel.ERROR) + environment['runtime']['debug'].writeDebugOut('\/-------environment-------\/',debug.debugLevel.INFO, onAnyLevel=True) + environment['runtime']['debug'].writeDebugOut(str(environment),debug.debugLevel.INFO, onAnyLevel=True) + environment['runtime']['debug'].writeDebugOut('\/-------settings.conf-------\/',debug.debugLevel.INFO, onAnyLevel=True) environment['runtime']['debug'].writeDebugOut(str(environment['settings']._sections -),debug.debugLevel.ERROR) +),debug.debugLevel.INFO, onAnyLevel=True) return environment