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