From bc5538c16c3f54ca732ed7daa94b6f5eb1f2bb33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= Date: Fri, 30 Nov 2012 10:18:18 +0100 Subject: [PATCH] moved parser for kernel radio options to tuned.utils.commands It is for getting the active option from strings like: [always] never In this case active is 'always'. --- tuned/plugins/plugin_disk.py | 6 +----- tuned/utils/commands.py | 9 +++++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tuned/plugins/plugin_disk.py b/tuned/plugins/plugin_disk.py index 3626764..ba63e1d 100644 --- a/tuned/plugins/plugin_disk.py +++ b/tuned/plugins/plugin_disk.py @@ -143,11 +143,7 @@ class DiskPlugin(base.Plugin): sys_file = self._elevator_file(device) # example of scheduler file content: # noop deadline [cfq] - schedulers = tuned.utils.commands.read_file(sys_file).split() - for scheduler in schedulers: - if scheduler[0] == "[" and scheduler[-1] == "]": - return scheduler[1:-1] - return schedulers[0] + return tuned.utils.commands.get_active_option(tuned.utils.commands.read_file(sys_file)) def _alpm_policy_files(self): policy_files = [] diff --git a/tuned/utils/commands.py b/tuned/utils/commands.py index 2be9caf..aec90ab 100644 --- a/tuned/utils/commands.py +++ b/tuned/utils/commands.py @@ -43,6 +43,15 @@ def execute(args): log.error("Executing %s error: %s" % (args[0], e)) return out +# Helper for parsing kernel options like: +# [always] never +# It will return 'always' +def get_active_option(options): + m = re.match(r'.*\[([^\]]+)\].*', options) + if m: + return m.group(1) + return options.split()[0] + def recommend_profile(): profile = consts.DEFAULT_PROFILE for f in consts.LOAD_DIRECTORIES: