merge argparse

This commit is contained in:
chrys 2017-05-05 23:21:24 +02:00
commit 6bece5f9c1
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 i18n
from core import settingsManager from core import settingsManager
from core import debug from core import debug
import argparse
class fenrirManager(): class fenrirManager():
def __init__(self): def __init__(self):
self.initialized = False
cliArgs = self.handleArgs()
if not cliArgs:
return
try: try:
self.environment = settingsManager.settingsManager().initFenrirConfig() self.environment = settingsManager.settingsManager().initFenrirConfig(cliArgs)
if not self.environment: if not self.environment:
raise RuntimeError('Cannot Initialize. Maybe the configfile is not available or not parseable') raise RuntimeError('Cannot Initialize. Maybe the configfile is not available or not parseable')
except RuntimeError: except RuntimeError:
raise raise
self.initialized = True
self.environment['runtime']['outputManager'].presentText(_("Start Fenrir"), soundIcon='ScreenReaderOn', interrupt=True) self.environment['runtime']['outputManager'].presentText(_("Start Fenrir"), soundIcon='ScreenReaderOn', interrupt=True)
signal.signal(signal.SIGINT, self.captureSignal) signal.signal(signal.SIGINT, self.captureSignal)
signal.signal(signal.SIGTERM, self.captureSignal) signal.signal(signal.SIGTERM, self.captureSignal)
self.wasCommand = False 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): def proceed(self):
if not self.initialized:
return
while(self.environment['general']['running']): while(self.environment['general']['running']):
try: try:
self.handleProcess() self.handleProcess()

View File

@ -206,14 +206,25 @@ class settingsManager():
if not key in self.env['input']['scriptKey']: if not key in self.env['input']['scriptKey']:
self.env['input']['scriptKey'].append(key) 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'] = debug.debug()
environment['runtime']['debug'].initialize(environment) environment['runtime']['debug'].initialize(environment)
# get fenrir settings root
if not os.path.exists(settingsRoot): if not os.path.exists(settingsRoot):
if os.path.exists(os.path.dirname(os.path.realpath(__main__.__file__)) +'/../../config/'): if os.path.exists(os.path.dirname(os.path.realpath(__main__.__file__)) +'/../../config/'):
settingsRoot = os.path.dirname(os.path.realpath(__main__.__file__)) +'/../../config/' settingsRoot = os.path.dirname(os.path.realpath(__main__.__file__)) +'/../../config/'
else: else:
return None 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 not os.path.exists(soundRoot):
if os.path.exists(os.path.dirname(os.path.realpath(__main__.__file__)) +'/../../config/sound/'): 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/' soundRoot = os.path.dirname(os.path.realpath(__main__.__file__)) +'/../../config/sound/'
@ -221,7 +232,7 @@ class settingsManager():
environment['runtime']['settingsManager'] = self environment['runtime']['settingsManager'] = self
environment['runtime']['settingsManager'].initialize(environment) environment['runtime']['settingsManager'].initialize(environment)
validConfig = environment['runtime']['settingsManager'].loadSettings(settingsRoot + '/settings/' + settingsFile) validConfig = environment['runtime']['settingsManager'].loadSettings(settingsFile)
if not validConfig: if not validConfig:
return None return None

View File

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