add debugManager and -p option for print only

This commit is contained in:
chrys 2017-08-11 16:07:31 +02:00
parent 9f7e0c7f3c
commit 83e32ed62c
7 changed files with 18 additions and 64 deletions

View File

@ -146,6 +146,7 @@ doubleTapTimeout=0.2
[general] [general]
debugLevel=0 debugLevel=0
debugMode=File
punctuationProfile=default punctuationProfile=default
punctuationLevel=some punctuationLevel=some
respectPunctuationPause=True respectPunctuationPause=True

View File

@ -148,6 +148,10 @@ doubleTapTimeout=0.2
[general] [general]
debugLevel=0 debugLevel=0
# debugMode sets where the debug output should send to:
# debugMode=File writes to /var/log/fenrir.log
# debugMode=Print just prints on the screen
debugMode=File
punctuationProfile=default punctuationProfile=default
punctuationLevel=some punctuationLevel=some
respectPunctuationPause=True respectPunctuationPause=True

View File

@ -42,7 +42,6 @@ fenrirMaxPitch=99
fenrirMinRate=80 fenrirMinRate=80
fenrirMaxRate=890 fenrirMaxRate=890
[braille] [braille]
enabled=False enabled=False
driver=dummyDriver driver=dummyDriver
@ -99,6 +98,10 @@ doubleTapTimeout=0.2
[general] [general]
debugLevel=1 debugLevel=1
# debugMode sets where the debug output should send to:
# debugMode=File writes to /var/log/fenrir.log
# debugMode=Print just prints on the screen
debugMode=File
punctuationProfile=default punctuationProfile=default
punctuationLevel=some punctuationLevel=some
respectPunctuationPause=True respectPunctuationPause=True

View File

@ -1,8 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
# Debugger module for the Fenrir screen reader.
from enum import Enum from enum import Enum
from datetime import datetime
class debugLevel(Enum): class debugLevel(Enum):
DEACTIVE = 0 DEACTIVE = 0
@ -13,60 +11,3 @@ class debugLevel(Enum):
return self.value return self.value
def __str__(self): def __str__(self):
return self.name return self.name
class debug():
def __init__(self, fileName='/var/log/fenrir.log'):
self._fileName = fileName
self._file = None
self._fileOpened = False
def initialize(self, environment):
self.env = environment
def shutdown(self):
self.closeDebugFile()
def __del__(self):
try:
self.shutdown()
except:
pass
def openDebugFile(self, fileName = ''):
self._fileOpened = False
if fileName != '':
self._fileName = fileName
if self._fileName != '':
self._file = open(self._fileName,'a')
self._fileOpened = True
def writeDebugOut(self, text, level = debugLevel.DEACTIVE, onAnyLevel=False):
if (self.env['runtime']['settingsManager'].getSettingAsInt('general','debugLevel') < int(level)) and \
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()
if onAnyLevel:
msg = 'ANY '+ str(level) + ' ' + 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')
def closeDebugFile(self):
if not self._fileOpened:
return False
if self._file != None:
self._file.close()
self._fileOpened = False
return True
def getDebugFile(self):
return self._fileName
def setDebugFile(self, fileName):
self.closeDebugFile()
self._fileName = fileName

View File

@ -37,6 +37,7 @@ class fenrirManager():
parser.add_argument('-s', '--setting', metavar='SETTING-FILE', default='/etc/fenrir/settings/settings.conf', help='Use a specified settingsfile') parser.add_argument('-s', '--setting', metavar='SETTING-FILE', default='/etc/fenrir/settings/settings.conf', help='Use a specified settingsfile')
parser.add_argument('-o', '--options', metavar='SECTION#SETTING=VALUE,..', default='', help='Overwrite options in given settings file') parser.add_argument('-o', '--options', metavar='SECTION#SETTING=VALUE,..', default='', help='Overwrite options in given settings file')
parser.add_argument('-d', '--debug', action='store_true', help='Turns on Debugmode') parser.add_argument('-d', '--debug', action='store_true', help='Turns on Debugmode')
parser.add_argument('-p', '--print', action='store_true', help='Print debug messages on screen')
try: try:
args = parser.parse_args() args = parser.parse_args()
except Exception as e: except Exception as e:

View File

@ -54,6 +54,7 @@ settingsData = {
}, },
'general':{ 'general':{
'debugLevel': debug.debugLevel.DEACTIVE, 'debugLevel': debug.debugLevel.DEACTIVE,
'debugMode': 'FILE',
'punctuationProfile':'default', 'punctuationProfile':'default',
'punctuationLevel': 'some', 'punctuationLevel': 'some',
'respectPunctuationPause':True, 'respectPunctuationPause':True,

View File

@ -9,6 +9,7 @@ currentdir = os.path.dirname(os.path.realpath(os.path.abspath(inspect.getfile(in
fenrirPath = os.path.dirname(currentdir) fenrirPath = os.path.dirname(currentdir)
from configparser import ConfigParser from configparser import ConfigParser
from core import debugManager
from core import processManager from core import processManager
from core import eventManager from core import eventManager
from core import inputManager from core import inputManager
@ -256,7 +257,7 @@ class settingsManager():
settingsRoot = '/etc/fenrir/' settingsRoot = '/etc/fenrir/'
settingsFile = cliArgs.setting settingsFile = cliArgs.setting
soundRoot = '/usr/share/sounds/fenrir/' soundRoot = '/usr/share/sounds/fenrir/'
environment['runtime']['debug'] = debug.debug() environment['runtime']['debug'] = debugManager.debugManager()
environment['runtime']['debug'].initialize(environment) environment['runtime']['debug'].initialize(environment)
# get fenrir settings root # get fenrir settings root
if not os.path.exists(settingsRoot): if not os.path.exists(settingsRoot):
@ -286,7 +287,9 @@ class settingsManager():
self.parseSettingArgs(cliArgs.options) self.parseSettingArgs(cliArgs.options)
if cliArgs.debug: if cliArgs.debug:
self.setOptionArgDict('general', 'debugLevel', 3) self.setOptionArgDict('general', 'debugLevel', 3)
if cliArgs.print:
self.setOptionArgDict('general', 'debugLevel', 3)
self.setOptionArgDict('general', 'debugMode', 'PRINT')
self.setFenrirKeys(self.getSetting('general','fenrirKeys')) self.setFenrirKeys(self.getSetting('general','fenrirKeys'))
self.setScriptKeys(self.getSetting('general','scriptKeys')) self.setScriptKeys(self.getSetting('general','scriptKeys'))