~launchpad-results/launchpad-results/trunk

« back to all changes in this revision

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

  • Committer: Marc Tardif
  • Date: 2011-09-19 21:09:02 UTC
  • Revision ID: marc.tardif@canonical.com-20110919210902-32f23dwivc6tua56
Changed results to only return the last state which fixes bug #852007.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
    AutoReload,
13
13
    Int,
14
14
    Reference,
 
15
    Store,
15
16
    )
16
17
 
 
18
from zope.cachedescriptors.property import Lazy
17
19
from zope.component import getUtility
18
20
from zope.interface import implements
19
21
 
20
22
from lazr.restful.interfaces import IServiceRootResource
21
23
 
 
24
from lpresults.repository.formats.pnp import pnp_vendor_to_int
 
25
 
22
26
from lpresults.hardware.interfaces.device import (
23
27
    IDevice,
24
28
    IDeviceSet,
47
51
    category_id = Int(name="category")
48
52
 
49
53
    bus = Reference(bus_id, DeviceBus.id)
50
 
    product = Reference(
51
 
        (bus_id, product_id, vendor_id),
52
 
        (DeviceProduct.bus_id, DeviceProduct.product_id,
53
 
            DeviceProduct.vendor_id))
54
54
    vendor = Reference(
55
55
        (bus_id, vendor_id),
56
56
        (DeviceVendor.bus_id, DeviceVendor.vendor_id))
82
82
    def __path_parts__(self):
83
83
        return ("devices", self.path,)
84
84
 
 
85
    @Lazy
 
86
    def product(self):
 
87
        # XXX Using find instead of a reference because the vendor_id
 
88
        #     might be null.
 
89
        return Store.of(self).find(
 
90
            DeviceProduct, bus_id=self.bus_id, product_id=self.product_id,
 
91
            vendor_id=self.vendor_id).one()
 
92
 
85
93
    @property
86
94
    def path(self):
87
95
        path = "%s:%.4X" % (self.bus_name, self.product_id or 0)
132
140
        vendor_name=None, product_id=None, vendor_id=None,
133
141
        subproduct_id=None, subvendor_id=None):
134
142
        """See `IDeviceSet`."""
 
143
        # XXX Special case for PNP where the vendor_id can be generated.
 
144
        if bus_name == "pnp":
 
145
            vendor_id = pnp_vendor_to_int(vendor_name)
135
146
        id = get_hardware_store().execute(
136
147
            "SELECT get_device(?, ?, ?, ?, ?, ?, ?, ?)",
137
148
            (bus_name, category_name, product_name, vendor_name,