initial use of debug framework
This commit is contained in:
parent
46afedf429
commit
1467fc1939
@ -139,6 +139,7 @@ class settingsManager():
|
||||
except:
|
||||
value = self.settings[section][setting]
|
||||
return value
|
||||
|
||||
def getSettingAsBool(self, environment, section, setting):
|
||||
value = False
|
||||
try:
|
||||
@ -146,6 +147,7 @@ class settingsManager():
|
||||
except:
|
||||
value = self.settings[section][setting]
|
||||
return value
|
||||
|
||||
def loadSpeechDriver(self, environment, driverName):
|
||||
if environment['runtime']['speechDriver'] != None:
|
||||
environment['runtime']['speechDriver'].shutdown()
|
||||
@ -170,6 +172,7 @@ class settingsManager():
|
||||
spec.loader.exec_module(driver_mod)
|
||||
environment['runtime']['screenDriver'] = driver_mod.screen()
|
||||
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 ''
|
||||
|
||||
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']['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
|
||||
|
||||
|
@ -8,43 +8,43 @@ 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
|
||||
|
||||
def closeDebugFile(self):
|
||||
if not self._fileOpened:
|
||||
return False
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user