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

« back to all changes in this revision

Viewing changes to plugins/system_info.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
import md5
 
22
import logging
 
23
 
 
24
from checkbox.plugin import Plugin
 
25
 
 
26
 
 
27
class SystemInfo(Plugin):
 
28
 
 
29
    optional_attributes = ["system_id"]
 
30
 
 
31
    def register(self, manager):
 
32
        super(SystemInfo, self).register(manager)
 
33
 
 
34
        # System report should be generated early.
 
35
        self._manager.reactor.call_on("report", self.report, -10)
 
36
 
 
37
    def report(self):
 
38
        system_id = self._config.system_id or self._persist.get("system_id")
 
39
        if not system_id:
 
40
            system = self._manager.registry.hal.computer.system
 
41
            if not system:
 
42
                return
 
43
 
 
44
            # Old versions of HAL didn't have the system namespace
 
45
            if "hardware" in system:
 
46
                hardware = system.hardware
 
47
            else:
 
48
                hardware = system
 
49
 
 
50
            fingerprint = md5.new()
 
51
            for field in [
 
52
                    system.info.product,
 
53
                    system.info.subsystem,
 
54
                    system.product,
 
55
                    system.vendor,
 
56
                    system.formfactor,
 
57
                    hardware.vendor,
 
58
                    hardware.product]:
 
59
                fingerprint.update(str(field))
 
60
 
 
61
            system_id = fingerprint.hexdigest()
 
62
            self._persist.set("system_id", system_id)
 
63
 
 
64
        message = system_id
 
65
        logging.info("System ID: %s", message)
 
66
        self._manager.reactor.fire("report-system_id", message)
 
67
 
 
68
 
 
69
factory = SystemInfo