scripts plugin: migrate to new plugin interface, clarify hack
This commit is contained in:
parent
b078feecdf
commit
6a8a1bf96c
1 changed files with 26 additions and 26 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue