~launchpad-results/launchpad-results/trunk

« back to all changes in this revision

Viewing changes to lib/lpresults/hardware/models/devicestate.py

  • Committer: Marc Tardif
  • Date: 2011-08-09 15:46:45 UTC
  • Revision ID: marc.tardif@canonical.com-20110809154645-i151emhk6onjggx5
Added hardware for systems and system units.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2010-2011 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
__metaclass__ = type
 
5
 
 
6
__all__ = [
 
7
    "DeviceState",
 
8
    ]
 
9
 
 
10
from storm.locals import (
 
11
    AutoReload,
 
12
    Int,
 
13
    Reference,
 
14
    )
 
15
 
 
16
from zope.interface import implements
 
17
 
 
18
from lpresults.database.constants import (
 
19
    INFINITY,
 
20
    UTC_NOW,
 
21
    )
 
22
from lazr.delegates import delegates
 
23
 
 
24
from lpresults.database.datetime import UTCDateTime
 
25
 
 
26
from lpresults.hardware.interfaces.device import IDevice
 
27
from lpresults.hardware.interfaces.devicestate import IDeviceState
 
28
from lpresults.hardware.models.device import Device
 
29
from lpresults.hardware.models.devicedriver import DeviceDriver
 
30
from lpresults.hardware.models.systemunithelper import SystemUnitHelper
 
31
 
 
32
 
 
33
class DeviceState(SystemUnitHelper):
 
34
 
 
35
    __storm_table__ = "devicestate"
 
36
 
 
37
    implements(IDeviceState)
 
38
    delegates(IDevice, context="device")
 
39
 
 
40
    id = Int(primary=True, allow_none=False, default=AutoReload)
 
41
    system_unit_id = Int(allow_none=False)
 
42
    device_id = Int(allow_none=False)
 
43
    subdevice_id = Int()
 
44
    driver_id = Int()
 
45
    date_created = UTCDateTime(allow_none=False, default=UTC_NOW)
 
46
    date_deleted = UTCDateTime(allow_none=False, default=INFINITY)
 
47
 
 
48
    device = Reference(device_id, Device.id)
 
49
    subdevice = Reference(subdevice_id, Device.id)
 
50
    driver = Reference(driver_id, DeviceDriver.id)
 
51
 
 
52
    def __init__(self, system_unit, device, subdevice=None, driver=None,
 
53
            date_created=None):
 
54
        super(DeviceState, self).__init__(system_unit)
 
55
        self.device = device
 
56
        self.subdevice = subdevice
 
57
        self.driver = driver
 
58
 
 
59
        if date_created is not None:
 
60
            self.date_created = date_created