2016-07-07 13:43:31 -04:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
# Debugger module for the Fenrir screen reader.
|
2016-07-07 15:40:10 -04:00
|
|
|
|
2016-07-08 06:20:49 -04:00
|
|
|
class debugLevel(Enum):
|
|
|
|
DEACTIVE = 0
|
|
|
|
ERROR = 1
|
|
|
|
WARNING = 2
|
|
|
|
INFO = 3
|
2016-07-07 13:43:31 -04:00
|
|
|
|
|
|
|
class debug():
|
2016-07-08 06:20:49 -04:00
|
|
|
def __init__(self, fileName='/var/log/fenrir.log', level = debugLevel.DEACTIVE):
|
2016-07-07 13:43:31 -04:00
|
|
|
self._level = level
|
2016-07-08 05:56:42 -04:00
|
|
|
self._fileName = fileName
|
|
|
|
self._file = ''
|
|
|
|
self._fileOpened = False
|
2016-07-07 13:43:31 -04:00
|
|
|
|
|
|
|
def openDebugFile(self, fileName = ''):
|
2016-07-08 05:56:42 -04:00
|
|
|
self._fileOpened = False
|
2016-07-07 13:43:31 -04:00
|
|
|
if fileName != '':
|
|
|
|
self._fileName = fileName
|
|
|
|
if self._fileName != '':
|
|
|
|
self.file = open(self._fileName,'w')
|
|
|
|
self._fileOpened = True
|
|
|
|
|
2016-07-08 06:20:49 -04:00
|
|
|
def writeDebugOut(self, envirionment, text, level = debugLevel.DEACTIVE):
|
2016-07-08 06:15:26 -04:00
|
|
|
if envirionment['settings']['debugLevel'] < level:
|
2016-07-08 05:56:42 -04:00
|
|
|
if self._fileOpened:
|
|
|
|
self.closeDebugFile()
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
if not self._fileOpened:
|
|
|
|
self.openDebugFile()
|
2016-07-08 06:06:09 -04:00
|
|
|
self.writeLog(environment, text, level):
|
2016-07-08 05:56:42 -04:00
|
|
|
|
2016-07-08 06:06:09 -04:00
|
|
|
def writeLog(self, environment, text, level:
|
2016-07-08 06:15:26 -04:00
|
|
|
if envirionment['settings']['debugLevel'] < level:
|
2016-07-07 13:43:31 -04:00
|
|
|
return False
|
2016-07-08 06:06:09 -04:00
|
|
|
if not self._fileOpened:
|
|
|
|
return False
|
2016-07-07 13:43:31 -04:00
|
|
|
self._file.write(text + '\n')
|
|
|
|
return True
|
|
|
|
|
|
|
|
def closeDebugFile(self):
|
|
|
|
if not self._fileOpened:
|
|
|
|
return False
|
|
|
|
self._file.close()
|
|
|
|
self._fileOpened = False
|
|
|
|
return True
|
|
|
|
|
|
|
|
def getDebugFile(self):
|
|
|
|
return self._fileName
|
|
|
|
|
|
|
|
def setDebugFile(self, fileName):
|
2016-07-08 05:56:42 -04:00
|
|
|
self.closeDebugFile()
|
|
|
|
if self._fileOpened:
|
|
|
|
self.openDebugFile(self, fileName):
|
|
|
|
|
2016-07-07 13:43:31 -04:00
|
|
|
|
|
|
|
|