2
from commands import getoutput
4
from hwtest.lib.template import convert_string
5
from hwtest.lib.environ import add_path, remove_path
7
from hwtest.plugin import Plugin
8
from hwtest.question import Question
11
class Manual(Question):
13
required_fields = Question.required_fields + ["path"]
15
def __getattr__(self, attr):
16
if attr is "description":
17
return self.get_description()
19
return super(Manual, self).__getattr__(attr)
21
def run_command(self):
23
output = getoutput(self.command)
24
remove_path(self.path)
27
def get_description(self):
29
output = self.run_command()
30
description = convert_string(self.data["description"], {'output': output})
32
description = self.data["description"]
36
class ManualQuestion(Plugin):
38
def __init__(self, config, question_factory=None):
39
super(ManualQuestion, self).__init__(config)
40
self._question_factory = question_factory or Manual
42
def register(self, manager):
43
super(ManualQuestion, self).register(manager)
44
self._manager.reactor.call_on(("manual", "add-question"),
47
def add_question(self, *args, **kwargs):
48
kwargs["path"] = self.config.scripts_path
49
question = self._question_factory(*args, **kwargs)
50
self._manager.reactor.fire(("prompt", "add-question"), question)
53
factory = ManualQuestion