2
def __init__(self, application):
3
self.application = application
6
"""Show the introduction page."""
10
"""Show each test page."""
2
import optparse, gettext
3
from gettext import gettext as _
5
from hwtest.application import ApplicationManager
6
from hwtest.constants import SHARE_DIR
7
from hwtest.excluder import Excluder
11
DIRECTION_PREVIOUS = 0
14
class UserInterface(object):
15
'''Abstract base class for encapsulating the workflow and common code for
16
any user interface implementation (like GTK, Qt, or CLI).
18
A concrete subclass must implement all the abstract ui_* methods.'''
21
self.gettext_domain = 'hwtest'
22
self.application = None
25
gettext.textdomain(self.gettext_domain)
30
category = self.ui_present_categories(_("Hardware Categories"),
31
_("Please specify the type of hardware being tested:"))
32
exclude_func = lambda test, category=category: \
33
category not in test.categories
36
manager_tests = self.application.get_tests()
37
tests = Excluder(manager_tests, exclude_func, exclude_func)
39
direction = DIRECTION_NEXT
40
while tests.has_next():
41
if direction == DIRECTION_NEXT:
43
elif direction == DIRECTION_PREVIOUS:
46
raise Exception, "invalid direction: %s" % direction
47
direction = self.ui_present_question(test, tests.has_prev(), tests.has_next())
49
# Exchange test results
52
secure_id = self.ui_present_exchange(error)
53
self.application.report.secure_id = secure_id
54
self.application.run()
55
error = self.application.plugin_manager.get_error()
60
self.application = ApplicationManager().create(self.options)
64
optparser = optparse.OptionParser('%prog [options]')
65
optparser.add_option("-q", "--questions", metavar="FILE",
66
default=os.path.join(SHARE_DIR, "questions.txt"),
67
help="The file containing certification questions.")
68
optparser.add_option("-d", "--data-path", metavar="PATH",
70
help="The directory to store data files in.")
71
optparser.add_option("-l", "--log", metavar="FILE",
72
help="The file to write the log to.")
73
optparser.add_option("--log-level",
75
help="One of debug, info, warning, error or critical.")
77
(self.options, self.args) = optparser.parse_args()
79
def ui_present_categories(self, title, text):
80
raise NotImplementedError, 'this function must be overridden by subclasses'
82
def ui_present_question(self, test, has_prev, has_next):
83
raise NotImplementedError, 'this function must be overridden by subclasses'
85
def ui_present_exchange(self, error):
86
raise NotImplementedError, 'this function must be overridden by subclasses'