From 6a8a1bf96c090b941da902243243848bf6b65789 Mon Sep 17 00:00:00 2001 From: Jan Vcelak Date: Mon, 28 Jan 2013 15:11:22 +0100 Subject: [PATCH] scripts plugin: migrate to new plugin interface, clarify hack --- tuned/plugins/plugin_script.py | 52 +++++++++++++++++----------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/tuned/plugins/plugin_script.py b/tuned/plugins/plugin_script.py index 0807adb..5c92094 100644 --- a/tuned/plugins/plugin_script.py +++ b/tuned/plugins/plugin_script.py @@ -10,39 +10,39 @@ class ScriptPlugin(base.Plugin): Plugin for running custom scripts with profile activation and deactivation. """ - def _post_init(self): - self._dynamic_tuning = False - self._scripts = [] - if self._options["script"] is None: - return - - self._scripts.extend(self._options["script"]) - - @classmethod - def tunable_devices(self): - return ["script"] - - @classmethod - def _get_default_options(cls): + def _get_config_options(self): return { "script" : None, } - def _call_scripts(self, arg = "start"): - for script in self._scripts: - log.info("Calling script %s with arg %s" % (script, arg)) + def _instance_init(self, instance): + instance._has_static_tuning = True + instance._has_dynamic_tuning = False + if instance.options["script"] is not None: + # FIXME: this hack origins in profiles merger + assert isinstance(instance.options["script"], list) + instance._scripts = instance.options["script"] + else: + instance._scripts = [] + + def _instance_cleanup(self, instance): + pass + + def _call_scripts(self, scripts, argument): + for script in scripts: + log.info("calling script '%s' with argument '%s'" % (script, argument)) try: - proc = Popen([script, arg], stdout=PIPE, stderr=PIPE, close_fds=True) + proc = Popen([script, argument], stdout=PIPE, stderr=PIPE, close_fds=True) out, err = proc.communicate() - if proc.returncode: - log.error("script %s error: %s" % (script, err[:-1])) + log.error("script '%s' error: %s" % (script, err[:-1])) except (OSError,IOError) as e: - log.error("Script %s error: %s" % (script, e)) - return True + log.error("script '%s' error: %s" % (script, e)) - def execute_commands(self): - self._call_scripts() + def _instance_apply_static(self, instance): + super(self.__class__, self)._instance_apply_static(instance) + self._call_scripts(instance._scripts, "start") - def cleanup_commands(self): - self._call_scripts("stop") + def _instance_unapply_static(self, instance): + self._call_scripts(reversed(instance._scripts), "stop") + super(self.__class__, self)._instance_unapply_static(instance)