~jocave/checkbox/hybrid-amd-gpu-mods

« back to all changes in this revision

Viewing changes to checkbox-old/plugins/system_info.py

  • Committer: Zygmunt Krynicki
  • Date: 2013-05-29 07:50:30 UTC
  • mto: This revision was merged to the branch mainline in revision 2153.
  • Revision ID: zygmunt.krynicki@canonical.com-20130529075030-ngwz245hs2u3y6us
checkbox: move current checkbox code into checkbox-old

This patch cleans up the top-level directory of the project into dedicated
sub-project directories. One for checkbox-old (the current checkbox and all the
associated stuff), one for plainbox and another for checkbox-ng.

There are some associated changes, such as updating the 'source' mode of
checkbox provider in plainbox, and fixing paths in various test scripts that we
have.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# This file is part of Checkbox.
 
3
#
 
4
# Copyright 2008 Canonical Ltd.
 
5
#
 
6
# Checkbox is free software: you can redistribute it and/or modify
 
7
# it under the terms of the GNU General Public License as published by
 
8
# the Free Software Foundation, either version 3 of the License, or
 
9
# (at your option) any later version.
 
10
#
 
11
# Checkbox is distributed in the hope that it will be useful,
 
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
# GNU General Public License for more details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License
 
17
# along with Checkbox.  If not, see <http://www.gnu.org/licenses/>.
 
18
#
 
19
import logging
 
20
 
 
21
from checkbox.lib.dmi import Dmi
 
22
from checkbox.lib.safe import safe_md5sum
 
23
 
 
24
from checkbox.properties import String
 
25
from checkbox.plugin import Plugin
 
26
 
 
27
 
 
28
class SystemInfo(Plugin):
 
29
 
 
30
    # System ID to exchange information with the server.
 
31
    system_id = String(required=False)
 
32
 
 
33
    def register(self, manager):
 
34
        super(SystemInfo, self).register(manager)
 
35
 
 
36
        self.persist = None
 
37
        self.resource = None
 
38
 
 
39
        for (rt, rh) in [
 
40
             ("begin-persist", self.begin_persist),
 
41
             ("report-dmi", self.report_dmi)]:
 
42
            self._manager.reactor.call_on(rt, rh)
 
43
 
 
44
        # System report should be generated early.
 
45
        self._manager.reactor.call_on("report", self.report, -10)
 
46
 
 
47
    def begin_persist(self, persist):
 
48
        self.persist = persist.root_at("system_info")
 
49
 
 
50
    def report_dmi(self, resources):
 
51
        for resource in resources:
 
52
           if resource.get("category") == "CHASSIS":
 
53
               self.resource = resource
 
54
 
 
55
    # TODO: report this upon gathering
 
56
    def report(self):
 
57
        if self.system_id:
 
58
            system_id = self.system_id
 
59
        elif self.persist and self.persist.has("system_id"):
 
60
            system_id = self.persist.get("system_id")
 
61
        else:
 
62
            system_id = None
 
63
 
 
64
        if not system_id:
 
65
            resource = self.resource
 
66
            if resource is None or "product" not in resource:
 
67
                return
 
68
 
 
69
            chassis_type = Dmi.chassis_name_to_type[resource["product"]]
 
70
 
 
71
            fingerprint = safe_md5sum()
 
72
            for field in [
 
73
                    "Computer",
 
74
                    "unknown",
 
75
                    chassis_type,
 
76
                    resource.get("vendor", ""),
 
77
                    resource.get("model", "")]:
 
78
                fingerprint.update(field)
 
79
 
 
80
            system_id = fingerprint.hexdigest()
 
81
            if self.persist:
 
82
                self.persist.set("system_id", system_id)
 
83
 
 
84
        message = system_id
 
85
        logging.info("System ID: %s", message)
 
86
        self._manager.reactor.fire("report-system_id", message)
 
87
 
 
88
 
 
89
factory = SystemInfo