1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#
# Copyright (c) 2008 Canonical
#
# Written by Marc Tardif <marc@interunion.ca>
#
# This file is part of Checkbox.
#
# Checkbox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Checkbox is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
#
from gettext import gettext as _
from checkbox.plugin import Plugin
class CategoryPrompt(Plugin):
optional_attributes = ["category"]
def register(self, manager):
super(CategoryPrompt, self).register(manager)
self._category = self.config.category
self._manager.reactor.call_on("prompt-category", self.prompt_category)
def prompt_category(self, interface):
registry = self._manager.registry
# Try to determine category from HAL formfactor
if not self._category:
formfactor = registry.hal.computer.system.formfactor
if formfactor is not "unknown":
self._category = formfactor
# Try to determine category from dpkg architecture
if not self._category:
architecture = registry.dpkg.architecture
if architecture is "sparc":
self._category = "server"
# Try to determine category from kernel version
if not self._category:
version = registry.hal.computer.system.kernel.version
if str(version).endswith("-server"):
self._category = "server"
# Prompt for the category explicitly
if not self._category:
self._category = interface.show_category(_("Category"),
_("Please select the category of your system."),
self._category)
self._manager.reactor.fire("interface-category", self._category)
factory = CategoryPrompt
|