~ubuntu-branches/ubuntu/precise/checkbox/precise

« back to all changes in this revision

Viewing changes to plugins/category_prompt.py

  • Committer: Bazaar Package Importer
  • Author(s): Marc Tardif
  • Date: 2009-01-20 16:46:15 UTC
  • Revision ID: james.westby@ubuntu.com-20090120164615-7iz6nmlef41h4vx2
Tags: 0.4
* Setup bzr-builddeb in native mode.
* Removed LGPL notice from the copyright file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Copyright (c) 2008 Canonical
 
3
#
 
4
# Written by Marc Tardif <marc@interunion.ca>
 
5
#
 
6
# This file is part of Checkbox.
 
7
#
 
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.
 
12
#
 
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.
 
17
#
 
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/>.
 
20
#
 
21
from gettext import gettext as _
 
22
 
 
23
from checkbox.plugin import Plugin
 
24
 
 
25
 
 
26
class CategoryPrompt(Plugin):
 
27
 
 
28
    optional_attributes = ["category"]
 
29
 
 
30
    def register(self, manager):
 
31
        super(CategoryPrompt, self).register(manager)
 
32
        self._manager.reactor.call_on("prompt-category", self.prompt_category)
 
33
 
 
34
    def prompt_category(self, interface):
 
35
        category = self._persist.get("category") or self._config.category
 
36
        registry = self._manager.registry
 
37
 
 
38
        # Try to determine category from HAL formfactor
 
39
        if not category:
 
40
            formfactor = registry.hal.computer.system.formfactor
 
41
            if formfactor is not "unknown":
 
42
                category = formfactor
 
43
 
 
44
        # Try to determine category from dpkg architecture
 
45
        if not category:
 
46
            architecture = registry.dpkg.architecture
 
47
            if architecture is "sparc":
 
48
                category = "server"
 
49
 
 
50
        # Try to determine category from kernel version
 
51
        if not category:
 
52
            version = registry.hal.computer.system.kernel.version
 
53
            if str(version).endswith("-server"):
 
54
                category = "server"
 
55
 
 
56
        # Prompt for the category explicitly
 
57
        if not category:
 
58
            category = interface.show_category(_("Category"),
 
59
                _("Please select the category of your system."),
 
60
                category)
 
61
 
 
62
        self._persist.set("category", category)
 
63
        self._manager.reactor.fire("report-category", category)
 
64
 
 
65
 
 
66
factory = CategoryPrompt