add initial argParser

This commit is contained in:
chrys 2017-05-05 20:59:38 +02:00
parent 06f69edb97
commit 1cbf7c1329
7 changed files with 41 additions and 13 deletions

0
play zone/charmapTTY.py Normal file → Executable file
View File

0
play zone/daemon.py Normal file → Executable file
View File

0
play zone/detectDevices.py Normal file → Executable file
View File

0
play zone/parseProcessTree.py Normal file → Executable file
View File

View File

@ -13,21 +13,39 @@ if not os.path.dirname(os.path.realpath(__main__.__file__)) in sys.path:
from core import i18n
from core import settingsManager
from core import debug
import argparse
class fenrirManager():
def __init__(self):
self.initialized = False
cliArgs = self.handleArgs()
if not cliArgs:
return
try:
self.environment = settingsManager.settingsManager().initFenrirConfig()
self.environment = settingsManager.settingsManager().initFenrirConfig(cliArgs)
if not self.environment:
raise RuntimeError('Cannot Initialize. Maybe the configfile is not available or not parseable')
except RuntimeError:
raise
self.initialized = True
self.environment['runtime']['outputManager'].presentText(_("Start Fenrir"), soundIcon='ScreenReaderOn', interrupt=True)
signal.signal(signal.SIGINT, self.captureSignal)
signal.signal(signal.SIGTERM, self.captureSignal)
self.wasCommand = False
def handleArgs(self):
args = None
parser = argparse.ArgumentParser(description="Fenrir Help")
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')
try:
args = parser.parse_args()
except Exception as e:
parser.print_help()
return args
def proceed(self):
if not self.initialized:
return
while(self.environment['generalInformation']['running']):
try:
self.handleProcess()

View File

@ -205,14 +205,25 @@ class settingsManager():
if not key in self.env['input']['scriptKey']:
self.env['input']['scriptKey'].append(key)
def initFenrirConfig(self, environment = environment.environment, settingsRoot = '/etc/fenrir/', settingsFile='settings.conf', soundRoot = '/usr/share/sounds/fenrir/'):
def initFenrirConfig(self, cliArgs, environment = environment.environment):
settingsRoot = '/etc/fenrir/'
settingsFile = cliArgs.setting
soundRoot = '/usr/share/sounds/fenrir/'
environment['runtime']['debug'] = debug.debug()
environment['runtime']['debug'].initialize(environment)
# get fenrir settings root
if not os.path.exists(settingsRoot):
if os.path.exists(os.path.dirname(os.path.realpath(__main__.__file__)) +'/../../config/'):
settingsRoot = os.path.dirname(os.path.realpath(__main__.__file__)) +'/../../config/'
else:
return None
# get settings file
if not os.path.exists(settingsFile):
if os.path.exists(settingsRoot + '/settings/' + settingsFile):
settingsFile = settingsRoot + '/settings/' + settingsFile
else:
return None
# get sound themes root
if not os.path.exists(soundRoot):
if os.path.exists(os.path.dirname(os.path.realpath(__main__.__file__)) +'/../../config/sound/'):
soundRoot = os.path.dirname(os.path.realpath(__main__.__file__)) +'/../../config/sound/'
@ -220,7 +231,7 @@ class settingsManager():
environment['runtime']['settingsManager'] = self
environment['runtime']['settingsManager'].initialize(environment)
validConfig = environment['runtime']['settingsManager'].loadSettings(settingsRoot + '/settings/' + settingsFile)
validConfig = environment['runtime']['settingsManager'].loadSettings(settingsFile)
if not validConfig:
return None

View File

@ -113,8 +113,8 @@ class driver():
continue
try:
open(deviceFile)
except:
print("Not readable Inputdevice : " + deviceFile +' ' + str(e))
except Exception as e:
self.env['runtime']['debug'].writeDebugOut("Not readable Inputdevice : " + deviceFile +' ' + str(e),debug.debugLevel.ERROR)
continue
# 3 pos absolute
# 2 pos relative
@ -126,26 +126,25 @@ class driver():
if mode in ['ALL','NOMICE']:
if eventType.EV_KEY in cap:
if 116 in cap[eventType.EV_KEY] and len(cap[eventType.EV_KEY]) < 10:
print('power')
continue
if len(cap[eventType.EV_KEY]) < 30:
print('Not A useful keyboared')
continue
if mode == 'ALL':
self.iDevices[currDevice.fd] = currDevice
self.grabDevice(currDevice.fd)
print('Device added (ALL):' + self.iDevices[currDevice.fd].name)
self.env['runtime']['debug'].writeDebugOut('Device added (ALL):' + self.iDevices[currDevice.fd].name, debug.debugLevel.INFO)
print()
elif mode == 'NOMICE':
if not ((eventType.EV_REL in cap) or (eventType.EV_ABS in cap)):
self.iDevices[currDevice.fd] = currDevice
self.grabDevice(currDevice.fd)
print('Device added (NOMICE):' + self.iDevices[currDevice.fd].name)
self.env['runtime']['debug'].writeDebugOut('Device added (NOMICE):' + self.iDevices[currDevice.fd].name,debug.debugLevel.INFO)
elif currDevice.name.upper() in mode.split(','):
self.iDevices[currDevice.fd] = currDevice
self.grabDevice(currDevice.fd)
print('Device added (Name):' + self.iDevices[currDevice.fd].name)
self.env['runtime']['debug'].writeDebugOut('Device added (Name):' + self.iDevices[currDevice.fd].name,debug.debugLevel.INFO)
except Exception as e:
print("Skip Inputdevice : " + deviceFile +' ' + str(e))
self.env['runtime']['debug'].writeDebugOut("Skip Inputdevice : " + deviceFile +' ' + str(e),debug.debugLevel.ERROR)
self.iDeviceNo = len(evdev.list_devices())
def mapEvent(self, event):