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

@ -105,7 +105,7 @@ class settingsManager():
environment['soundIcons'][soundIcon] = FilePath
siConfig.close()
return environment
def loadSettings(self, environment, settingConfigPath='../../config/settings/settings.conf'):
environment['settings'] = ConfigParser()
#if not exist what is ?????
@ -131,7 +131,7 @@ class settingsManager():
except:
value = self.settings[section][setting]
return value
def getSettingAsFloat(self, environment, section, setting):
value = 0.0
try:
@ -139,13 +139,15 @@ class settingsManager():
except:
value = self.settings[section][setting]
return value
def getSettingAsBool(self, environment, section, setting):
value = False
try:
value = environment['settings'].getboolean(section, setting)
except:
value = self.settings[section][setting]
return value
return value
def loadSpeechDriver(self, environment, driverName):
if environment['runtime']['speechDriver'] != None:
environment['runtime']['speechDriver'].shutdown()
@ -169,7 +171,8 @@ class settingsManager():
driver_mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(driver_mod)
environment['runtime']['screenDriver'] = driver_mod.screen()
return environment
return environment
def setFenrirKeys(self, environment, keys):
keyList = keys.split(',')
for key in keyList:
@ -178,20 +181,20 @@ class settingsManager():
if not keyID in environment['input']['fenrirKey']:
environment['input']['fenrirKey'].append(keyID)
return environment
def keyIDasString(self, key):
try:
KeyID = self.getCodeForKeyID(key)
return str(KeyID)
except:
return ''
return ''
def initFenrirConfig(self):
return self.reInitFenrirConfig(environment.environment)
def reInitFenrirConfig(self, environment, settingsRoot = '../../config/'):
environment['runtime']['settingsManager'] = self
environment['runtime']['inputManager'] = inputManager.inputManager()
environment['runtime']['outputManager'] = outputManager.outputManager()
environment['runtime']['settingsManager'] = self
environment['runtime']['debug'] = debug.debug()
environment = environment['runtime']['settingsManager'].loadSettings(environment)
environment = self.setFenrirKeys(environment, self.getSetting(environment, 'general','fenrirKeys'))
if not os.path.exists(self.getSetting(environment, 'keyboard','keyboardLayout')):
@ -212,16 +215,24 @@ class settingsManager():
else:
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 = environment['runtime']['commandManager'].loadCommands(environment,'commands')
environment = environment['runtime']['commandManager'].loadCommands(environment,'onInput')
environment = environment['runtime']['commandManager'].loadCommands(environment,'onScreenChanged')
environment['runtime']['debug'] = debug.debug()
environment = environment['runtime']['settingsManager'].loadSpeechDriver(environment,\
environment['runtime']['settingsManager'].getSetting(environment,'speech', 'driver'))
environment = environment['runtime']['settingsManager'].loadScreenDriver(environment,\
environment['runtime']['settingsManager'].getSetting(environment,'screen', 'driver'))
environment = environment['runtime']['settingsManager'].loadSoundDriver(environment,\
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

View File

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