improve debug

This commit is contained in:
chrys 2016-10-12 23:14:58 +02:00
parent f785b3e6db
commit 876be9a6d3
3 changed files with 18 additions and 13 deletions

View File

@ -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)

View File

@ -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')

View File

@ -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