initial use of debug framework

This commit is contained in:
chrys 2016-08-21 23:26:19 +02:00
parent 46afedf429
commit 1467fc1939
2 changed files with 38 additions and 28 deletions

View File

@ -139,6 +139,7 @@ class settingsManager():
except: except:
value = self.settings[section][setting] value = self.settings[section][setting]
return value return value
def getSettingAsBool(self, environment, section, setting): def getSettingAsBool(self, environment, section, setting):
value = False value = False
try: try:
@ -146,6 +147,7 @@ class settingsManager():
except: except:
value = self.settings[section][setting] value = self.settings[section][setting]
return value return value
def loadSpeechDriver(self, environment, driverName): def loadSpeechDriver(self, environment, driverName):
if environment['runtime']['speechDriver'] != None: if environment['runtime']['speechDriver'] != None:
environment['runtime']['speechDriver'].shutdown() environment['runtime']['speechDriver'].shutdown()
@ -170,6 +172,7 @@ class settingsManager():
spec.loader.exec_module(driver_mod) spec.loader.exec_module(driver_mod)
environment['runtime']['screenDriver'] = driver_mod.screen() environment['runtime']['screenDriver'] = driver_mod.screen()
return environment return environment
def setFenrirKeys(self, environment, keys): def setFenrirKeys(self, environment, keys):
keyList = keys.split(',') keyList = keys.split(',')
for key in keyList: for key in keyList:
@ -178,20 +181,20 @@ class settingsManager():
if not keyID in environment['input']['fenrirKey']: if not keyID in environment['input']['fenrirKey']:
environment['input']['fenrirKey'].append(keyID) environment['input']['fenrirKey'].append(keyID)
return environment return environment
def keyIDasString(self, key): def keyIDasString(self, key):
try: try:
KeyID = self.getCodeForKeyID(key) KeyID = self.getCodeForKeyID(key)
return str(KeyID) return str(KeyID)
except: except:
return '' return ''
def initFenrirConfig(self): def initFenrirConfig(self):
return self.reInitFenrirConfig(environment.environment) return self.reInitFenrirConfig(environment.environment)
def reInitFenrirConfig(self, environment, settingsRoot = '../../config/'): def reInitFenrirConfig(self, environment, settingsRoot = '../../config/'):
environment['runtime']['settingsManager'] = self environment['runtime']['settingsManager'] = self
environment['runtime']['inputManager'] = inputManager.inputManager() environment['runtime']['debug'] = debug.debug()
environment['runtime']['outputManager'] = outputManager.outputManager()
environment = environment['runtime']['settingsManager'].loadSettings(environment) environment = environment['runtime']['settingsManager'].loadSettings(environment)
environment = self.setFenrirKeys(environment, self.getSetting(environment, 'general','fenrirKeys')) environment = self.setFenrirKeys(environment, self.getSetting(environment, 'general','fenrirKeys'))
if not os.path.exists(self.getSetting(environment, 'keyboard','keyboardLayout')): if not os.path.exists(self.getSetting(environment, 'keyboard','keyboardLayout')):
@ -212,16 +215,24 @@ class settingsManager():
else: else:
environment = environment['runtime']['settingsManager'].loadSoundIcons(environment, self.getSetting(environment, 'sound','theme')) environment = environment['runtime']['settingsManager'].loadSoundIcons(environment, self.getSetting(environment, 'sound','theme'))
environment['runtime']['inputManager'] = inputManager.inputManager()
environment['runtime']['outputManager'] = outputManager.outputManager()
environment['runtime']['commandManager'] = commandManager.commandManager() environment['runtime']['commandManager'] = commandManager.commandManager()
environment = environment['runtime']['commandManager'].loadCommands(environment,'commands') environment = environment['runtime']['commandManager'].loadCommands(environment,'commands')
environment = environment['runtime']['commandManager'].loadCommands(environment,'onInput') environment = environment['runtime']['commandManager'].loadCommands(environment,'onInput')
environment = environment['runtime']['commandManager'].loadCommands(environment,'onScreenChanged') environment = environment['runtime']['commandManager'].loadCommands(environment,'onScreenChanged')
environment['runtime']['debug'] = debug.debug()
environment = environment['runtime']['settingsManager'].loadSpeechDriver(environment,\ environment = environment['runtime']['settingsManager'].loadSpeechDriver(environment,\
environment['runtime']['settingsManager'].getSetting(environment,'speech', 'driver')) environment['runtime']['settingsManager'].getSetting(environment,'speech', 'driver'))
environment = environment['runtime']['settingsManager'].loadScreenDriver(environment,\ environment = environment['runtime']['settingsManager'].loadScreenDriver(environment,\
environment['runtime']['settingsManager'].getSetting(environment,'screen', 'driver')) environment['runtime']['settingsManager'].getSetting(environment,'screen', 'driver'))
environment = environment['runtime']['settingsManager'].loadSoundDriver(environment,\ environment = environment['runtime']['settingsManager'].loadSoundDriver(environment,\
environment['runtime']['settingsManager'].getSetting(environment,'sound', 'driver')) environment['runtime']['settingsManager'].getSetting(environment,'sound', 'driver'))
environment['runtime']['debug'].writeDebugOut(environment,'\/-------environment-------\/',debug.debugLevel.ERROR)
environment['runtime']['debug'].writeDebugOut(environment,str(environment),debug.debugLevel.ERROR)
environment['runtime']['debug'].writeDebugOut(environment,'\/-------settings.conf-------\/',debug.debugLevel.ERROR)
environment['runtime']['debug'].writeDebugOut(environment,str(environment['settings']._sections
),debug.debugLevel.ERROR)
return environment return environment

View File

@ -8,43 +8,43 @@ class debugLevel(Enum):
ERROR = 1 ERROR = 1
WARNING = 2 WARNING = 2
INFO = 3 INFO = 3
def __int__(self):
return self.value
class debug(): class debug():
def __init__(self, fileName='/var/log/fenrir.log', level = debugLevel.DEACTIVE): def __init__(self, fileName='/var/log/fenrir.log'):
self._level = level
self._fileName = fileName self._fileName = fileName
self._file = '' self._file = None
self._fileOpened = False self._fileOpened = False
def __del__(self):
try:
self.closeDebugFile()
except:
pass
def openDebugFile(self, fileName = ''): def openDebugFile(self, fileName = ''):
self._fileOpened = False self._fileOpened = False
if fileName != '': if fileName != '':
self._fileName = fileName self._fileName = fileName
if self._fileName != '': if self._fileName != '':
self.file = open(self._fileName,'w') self._file = open(self._fileName,'w')
self._fileOpened = True self._fileOpened = True
def writeDebugOut(self, envirionment, text, level = debugLevel.DEACTIVE): def writeDebugOut(self, environment, text, level = debugLevel.DEACTIVE):
if envirionment['settings']['debugLevel'] < level: if environment['runtime']['settingsManager'].getSettingAsInt(environment, 'general','debugLevel') < int(level):
if self._fileOpened: if self._fileOpened:
self.closeDebugFile() self.closeDebugFile()
return return
else: else:
if not self._fileOpened: if not self._fileOpened:
self.openDebugFile() self.openDebugFile()
self.writeLog(environment, text, level)
def writeLog(self, environment, text, level = debugLevel.DEACTIVE):
if envirionment['settings']['debugLevel'] < level:
return False
if not self._fileOpened:
return False
self._file.write(text + '\n') self._file.write(text + '\n')
return True
def closeDebugFile(self): def closeDebugFile(self):
if not self._fileOpened: if not self._fileOpened:
return False return False
if self._file != None:
self._file.close() self._file.close()
self._fileOpened = False self._fileOpened = False
return True return True
@ -54,8 +54,7 @@ class debug():
def setDebugFile(self, fileName): def setDebugFile(self, fileName):
self.closeDebugFile() self.closeDebugFile()
if self._fileOpened: self._fileName = fileName
self.openDebugFile(self, fileName)