From b7981e7b5ea926d6128219105145b83cce2f03e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= Date: Mon, 8 Jun 2015 13:44:48 +0200 Subject: [PATCH] functions: added cpulist_unpack built-in function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Usage: [variables] cpus = ${f:cpulist_unpack:1,2,3-5} The 'cpus' will be set to '1,2,3,4,5'. Also the built-in function can take arbitrary number of arguments which will be concatenated, e.g.: [variables] cpus = ${f:cpulist_unpack:1-3,5:6-7,9} This means two arguments to 'cpulist_unpack' function. The first argument: '1-3,5' and the second '6-7,9'. The result: '1,2,3,5,6,7,9'. Also renamed internal function 'unpack_cpulist' to 'cpulist_unpack' to be more consistent. Signed-off-by: Jaroslav Škarvada --- .../functions/function_cpulist_unpack.py | 19 +++++++++++++++++++ tuned/utils/commands.py | 6 +++--- 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 tuned/profiles/functions/function_cpulist_unpack.py diff --git a/tuned/profiles/functions/function_cpulist_unpack.py b/tuned/profiles/functions/function_cpulist_unpack.py new file mode 100644 index 0000000..f44f9c9 --- /dev/null +++ b/tuned/profiles/functions/function_cpulist_unpack.py @@ -0,0 +1,19 @@ +import os +import tuned.logs +import base +from tuned.utils.commands import commands + +log = tuned.logs.get() + +class cpulist_unpack(base.Function): + """ + Conversion function: unpacks CPU list in form 1-3,4 to 1,2,3,4 + """ + def __init__(self): + # arbitrary number of arguments + super(self.__class__, self).__init__("cpulist_unpack", 0) + + def execute(self, args): + if not super(self.__class__, self).execute(args): + return None + return ",".join(str(v) for v in self._cmd.cpulist_unpack(",".join(args))) diff --git a/tuned/utils/commands.py b/tuned/utils/commands.py index ec3f648..e279d1c 100644 --- a/tuned/utils/commands.py +++ b/tuned/utils/commands.py @@ -136,7 +136,7 @@ class commands: return cpus # Unpacks CPU list, i.e. 1-3 will be converted to 1, 2, 3 - def unpack_cpulist(self, l): + def cpulist_unpack(self, l): rl = [] if l is None: return l @@ -157,10 +157,10 @@ class commands: if l is None: return None m = 0 - ul = self.unpack_cpulist(l) + ul = self.cpulist_unpack(l) if ul is None: return None - for v in self.unpack_cpulist(l): + for v in ul: m |= pow(2, v) return "0x%08x" % m