From 63558e96c14a89973656d4d68633089ce51c384b Mon Sep 17 00:00:00 2001 From: Jan Vcelak Date: Wed, 23 Jan 2013 18:49:45 +0100 Subject: [PATCH] plugin commands: add numeric priority to enforce execution order --- tuned/plugins/base.py | 7 ++++++- tuned/plugins/decorators.py | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tuned/plugins/base.py b/tuned/plugins/base.py index e1cb749..6328d6d 100644 --- a/tuned/plugins/base.py +++ b/tuned/plugins/base.py @@ -227,7 +227,7 @@ class Plugin(object): """ Initialize commands. """ - self._commands = {} + self._commands = collections.OrderedDict() self._autoregister_commands() self._check_commands() @@ -249,14 +249,19 @@ class Plugin(object): info["custom"] = None info["set"] = member info["per_device"] = member._command["per_device"] + info["priority"] = member._command["priority"] elif "get" in member._command: info["get"] = member elif "custom" in member._command: info["custom"] = member info["per_device"] = member._command["per_device"] + info["priority"] = member._command["priority"] self._commands[command_name] = info + # sort commands by priority + self._commands = collections.OrderedDict(sorted(self._commands.iteritems(), key=lambda (name, info): info["priority"])) + def _check_commands(self): """ Check if all commands are defined correctly. diff --git a/tuned/plugins/decorators.py b/tuned/plugins/decorators.py index bed1ae4..491d863 100644 --- a/tuned/plugins/decorators.py +++ b/tuned/plugins/decorators.py @@ -17,12 +17,13 @@ __all__ = ["command_set", "command_get", "command_custom"] # return current_foo # -def command_set(name, per_device=False): +def command_set(name, per_device=False, priority=0): def wrapper(method): method._command = { "set": True, "name": name, "per_device": per_device, + "priority": priority, } return method @@ -37,12 +38,13 @@ def command_get(name): return method return wrapper -def command_custom(name, per_device=False): +def command_custom(name, per_device=False, priority=0): def wrapper(method): method._command = { "custom": True, "name": name, "per_device": per_device, + "priority": priority, } return method return wrapper