From 02ef75d966fd7ecdeb299f7aaeefc18649391ebe Mon Sep 17 00:00:00 2001 From: chrys Date: Tue, 18 Oct 2016 19:42:04 +0200 Subject: [PATCH] look at /usr/share/sounds/fenrir for sound --- config/settings/settings.conf | 1 + config/settings/settings.conf.chrys | 1 + config/settings/settings.conf.storm | 1 + src/fenrir/core/commandManager.py | 33 +++++++++++++++++++++++++++-- src/fenrir/core/settings.py | 1 + src/fenrir/core/settingsManager.py | 11 ++++++---- 6 files changed, 42 insertions(+), 6 deletions(-) diff --git a/config/settings/settings.conf b/config/settings/settings.conf index 989d701a..e37308f5 100644 --- a/config/settings/settings.conf +++ b/config/settings/settings.conf @@ -110,6 +110,7 @@ timeFormat=%H:%M:%P dateFormat=%A, %B %d, %Y autoSpellCheck=True spellCheckLanguage=en_US +scriptPath=/etc/fenrir/scripts [promote] enabled=True diff --git a/config/settings/settings.conf.chrys b/config/settings/settings.conf.chrys index 27501272..d690dffc 100644 --- a/config/settings/settings.conf.chrys +++ b/config/settings/settings.conf.chrys @@ -110,6 +110,7 @@ timeFormat=%H:%M:%P dateFormat=%A, %B %d, %Y autoSpellCheck=True spellCheckLanguage=en_US +scriptPath=/etc/fenrir/scripts [promote] enabled=True diff --git a/config/settings/settings.conf.storm b/config/settings/settings.conf.storm index 6ebb346b..be89c6f1 100644 --- a/config/settings/settings.conf.storm +++ b/config/settings/settings.conf.storm @@ -60,6 +60,7 @@ timeFormat=%H:%M:%P dateFormat="%A, %B %d, %Y" autoSpellCheck=True spellCheckLanguage=en_US +scriptPath=/etc/fenrir/scripts [promote] enabled=True diff --git a/src/fenrir/core/commandManager.py b/src/fenrir/core/commandManager.py index 36d8d97f..79524251 100644 --- a/src/fenrir/core/commandManager.py +++ b/src/fenrir/core/commandManager.py @@ -20,7 +20,7 @@ class commandManager(): self.env['runtime']['commandManager'].loadCommands('onScreenChanged') self.env['runtime']['commandManager'].loadCommands('onApplicationChange') self.env['runtime']['commandManager'].loadCommands('onSwitchApplicationProfile') - + self.env['runtime']['commandManager'].loadScriptCommands() def shutdown(self): self.env['runtime']['commandManager'].shutdownCommands('commands') self.env['runtime']['commandManager'].shutdownCommands('onInput') @@ -51,7 +51,36 @@ class commandManager(): self.env['runtime']['debug'].writeDebugOut("Loading command:" + command ,debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) continue - + + def loadScriptCommands(self, section='commands'): + scriptPath = self.env['runtime']['settingsManager'].getSetting('general', 'scriptPath') + if not os.path.exists(scriptPath): + self.env['runtime']['debug'].writeDebugOut("scriptpath not exists:" + scriptPath ,debug.debugLevel.ERROR) + return + if not os.path.isdir(scriptPath): + self.env['runtime']['debug'].writeDebugOut("scriptpath not a directory:" + scriptPath ,debug.debugLevel.ERROR) + return + if not os.access(scriptPath, os.R_OK): + self.env['runtime']['debug'].writeDebugOut("scriptpath not readable:" + scriptPath ,debug.debugLevel.ERROR) + return + commandList = glob.glob(self.env['runtime']['settingsManager'].getSetting('general', 'scriptPath')+'/*') + for command in commandList: + try: + fileName, fileExtension = os.path.splitext(command) + fileName = fileName.split('/')[-1] + if fileName.startswith('__'): + continue + spec = importlib.util.spec_from_file_location(__main__.__file__+'/commands/commands/subprocess.py', command) + command_mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(command_mod) + self.env['commands'][section][fileName.upper()] = command_mod.command() + self.env['commands'][section][fileName.upper()].initialize(self.env,command) + self.env['runtime']['debug'].writeDebugOut("Load script:" + section + "." + fileName.upper() ,debug.debugLevel.INFO, onAnyLevel=True) + except Exception as e: + print(e) + self.env['runtime']['debug'].writeDebugOut("Loading script:" + command ,debug.debugLevel.ERROR) + self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) + continue def shutdownCommands(self, section): for command in sorted(self.env['commands'][section]): try: diff --git a/src/fenrir/core/settings.py b/src/fenrir/core/settings.py index 4370a78a..19210810 100644 --- a/src/fenrir/core/settings.py +++ b/src/fenrir/core/settings.py @@ -53,6 +53,7 @@ settings = { 'dateFormat': '%A, %B %d, %Y', 'autoSpellCheck': False, 'spellCheckLanguage': 'en_US', + 'scriptPath':'/etc/fenrir/scripts', }, 'promote':{ 'enabled': True, diff --git a/src/fenrir/core/settingsManager.py b/src/fenrir/core/settingsManager.py index d8601576..b18e4cd5 100644 --- a/src/fenrir/core/settingsManager.py +++ b/src/fenrir/core/settingsManager.py @@ -192,7 +192,7 @@ class settingsManager(): for key in keyList: 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'): + def initFenrirConfig(self, environment = environment.environment, settingsRoot = '/etc/fenrir/', settingsFile='settings.conf', soundRoot = '/usr/share/sounds/fenrir'): environment['runtime']['debug'] = debug.debug() environment['runtime']['debug'].initialize(environment) if not os.path.exists(settingsRoot): @@ -200,7 +200,10 @@ class settingsManager(): settingsRoot = os.path.dirname(os.path.realpath(__main__.__file__)) +'/../../config/' else: return None - + if not os.path.exists(soundRoot): + if os.path.exists(os.path.dirname(os.path.realpath(__main__.__file__)) +'/../../config/'): + soundRoot = os.path.dirname(os.path.realpath(__main__.__file__)) +'/../../config/' + environment['runtime']['settingsManager'] = self environment['runtime']['settingsManager'].initialize(environment) @@ -220,8 +223,8 @@ class settingsManager(): environment['runtime']['settingsManager'].loadShortcuts(self.getSetting('keyboard','keyboardLayout')) if not os.path.exists(self.getSetting('sound','theme') + '/soundicons.conf'): - if os.path.exists(settingsRoot + 'sound/'+ self.getSetting('sound','theme')): - self.setSetting('sound', 'theme', settingsRoot + 'sound/'+ self.getSetting('sound','theme')) + if os.path.exists(soundRoot + 'sound/'+ self.getSetting('sound','theme')): + self.setSetting('sound', 'theme', soundRoot + 'sound/'+ self.getSetting('sound','theme')) if os.path.exists(self.getSetting('sound','theme') + '/soundicons.conf'): environment['runtime']['settingsManager'].loadSoundIcons(self.getSetting('sound','theme')) else: