Exemplo n.º 1
0
def make_submission_device_statistics_clause(
    bus, vendor_id, product_id, driver_name, package_name,
    device_ids_required):
    """Create a where expression and a table list for selecting devices.
    """
    tables = [HWSubmissionDevice, HWDeviceDriverLink]
    where_clauses = [
        HWSubmissionDevice.device_driver_link == HWDeviceDriverLink.id,
        ]

    if device_ids_required:
        if bus is None or vendor_id is None or product_id is None:
            raise ParameterError("Device IDs are required.")
    else:
        device_specified = [
            param
            for param in (bus, vendor_id, product_id)
            if param is not None]

        if len(device_specified) not in (0, 3):
            raise ParameterError(
                'Either specify bus, vendor_id and product_id or none of '
                'them.')
        if bus is None and driver_name is None:
            raise ParameterError(
                'Specify (bus, vendor_id, product_id) or driver_name.')
    if bus is not None:
        tables.extend([HWVendorID, HWDevice])
        where_clauses.extend([
            HWVendorID.bus == bus,
            HWVendorID.vendor_id_for_bus == vendor_id,
            HWDevice.bus_vendor == HWVendorID.id,
            HWDeviceDriverLink.device == HWDevice.id,
            HWDevice.bus_product_id == product_id])

    if driver_name is None and package_name is None:
        where_clauses.append(HWDeviceDriverLink.driver == None)
    else:
        tables.append(HWDriver)
        where_clauses.append(HWDeviceDriverLink.driver == HWDriver.id)
        if driver_name is not None:
            where_clauses.append(HWDriver.name == driver_name)
        if package_name is not None:
            if package_name == '':
                # XXX Abel Deuring, 2009-05-07, bug=306265. package_name
                # should be declared notNull=True. For now, we must query
                # for the empty string as well as for None.
                where_clauses.append(
                    Or(HWDriver.package_name == package_name,
                       HWDriver.package_name == None))
            else:
                where_clauses.append(HWDriver.package_name == package_name)

    return tables, where_clauses
Exemplo n.º 2
0
 def getByBusAndVendorID(self, bus, vendor_id):
     """See `IHWVendorIDSet`."""
     if not isValidVendorID(bus, vendor_id):
         raise ParameterError(
             '%s is not a valid vendor ID for %s'
             % (repr(vendor_id), bus.title))
     return HWVendorID.selectOneBy(bus=bus, vendor_id_for_bus=vendor_id)
Exemplo n.º 3
0
 def getByDeviceID(self, bus, vendor_id, product_id, variant=None):
     """See `IHWDeviceSet`."""
     if not isValidProductID(bus, product_id):
         raise ParameterError(
             '%s is not a valid product ID for %s'
             % (repr(product_id), bus.title))
     bus_vendor = HWVendorIDSet().getByBusAndVendorID(bus, vendor_id)
     return HWDevice.selectOneBy(bus_vendor=bus_vendor,
                                 bus_product_id=product_id,
                                 variant=variant)
Exemplo n.º 4
0
    def hwInfoByBugRelatedUsers(
        self, bug_ids=None, bug_tags=None, affected_by_bug=False,
        subscribed_to_bug=False, user=None):
        """See `IHWSubmissionSet`."""
        if ((bug_ids is None or len(bug_ids) == 0) and
            (bug_tags is None or len(bug_tags) == 0)):
            raise ParameterError('bug_ids or bug_tags must be supplied.')

        tables = [
            Person, HWSubmission, HWSubmissionDevice, HWDeviceDriverLink,
            HWDevice, HWVendorID, Bug, BugTag,
            ]

        clauses = [
            Person.id == HWSubmission.ownerID,
            HWSubmissionDevice.submission == HWSubmission.id,
            HWSubmissionDevice.device_driver_link == HWDeviceDriverLink.id,
            HWDeviceDriverLink.device == HWDevice.id,
            HWDevice.bus_vendor == HWVendorID.id]

        if bug_ids is not None and bug_ids is not []:
            clauses.append(Bug.id.is_in(bug_ids))

        if bug_tags is not None and bug_tags is not []:
            clauses.extend(
                [Bug.id == BugTag.bugID, BugTag.tag.is_in(bug_tags)])

        clauses.append(_userCanAccessSubmissionStormClause(user))

        person_clauses = [Bug.ownerID == HWSubmission.ownerID]
        if subscribed_to_bug:
            person_clauses.append(
                And(BugSubscription.person_id == HWSubmission.ownerID,
                    BugSubscription.bug == Bug.id))
            tables.append(BugSubscription)
        if affected_by_bug:
            person_clauses.append(
                And(BugAffectsPerson.personID == HWSubmission.ownerID,
                    BugAffectsPerson.bug == Bug.id,
                    BugAffectsPerson.affected))
            tables.append(BugAffectsPerson)
        clauses.append(Or(person_clauses))

        query = Select(
            columns=[
                Person.name, HWVendorID.bus,
                HWVendorID.vendor_id_for_bus, HWDevice.bus_product_id],
            tables=tables, where=And(*clauses), distinct=True,
            order_by=[HWVendorID.bus, HWVendorID.vendor_id_for_bus,
                      HWDevice.bus_product_id, Person.name])

        return [
            (person_name, HWBus.items[bus_id], vendor_id, product_id)
             for person_name, bus_id, vendor_id, product_id
             in IStore(HWSubmission).execute(query)]
Exemplo n.º 5
0
 def getDistroTarget(self, distribution, distroseries, distroarchseries):
     distro_targets = [
         target for target in (distribution, distroseries, distroarchseries)
         if target is not None
     ]
     if len(distro_targets) == 0:
         return None
     elif len(distro_targets) == 1:
         return distro_targets[0]
     else:
         raise ParameterError(
             'Only one of `distribution`, `distroseries` or '
             '`distroarchseries` can be present.')
Exemplo n.º 6
0
 def search(self, bus, vendor_id, product_id=None):
     """See `IHWDeviceSet`."""
     bus_vendor = HWVendorIDSet().getByBusAndVendorID(bus, vendor_id)
     args = []
     if product_id is not None:
         if not isValidProductID(bus, product_id):
             raise ParameterError(
                 '%s is not a valid product ID for %s'
                 % (repr(product_id), bus.title))
         args.append(HWDevice.bus_product_id == product_id)
     return IStore(HWDevice).find(
         HWDevice, HWDevice.bus_vendor == bus_vendor, *args).order_by(
             HWDevice.id)
Exemplo n.º 7
0
 def _create(self, id, **kw):
     bus_vendor = kw.get('bus_vendor')
     if bus_vendor is None:
         raise TypeError('HWDevice() did not get expected keyword '
                         'argument bus_vendor')
     bus_product_id = kw.get('bus_product_id')
     if bus_product_id is None:
         raise TypeError('HWDevice() did not get expected keyword '
                         'argument bus_product_id')
     if not isValidProductID(bus_vendor.bus, bus_product_id):
         raise ParameterError(
             '%s is not a valid product ID for %s'
             % (repr(bus_product_id), bus_vendor.bus.title))
     SQLBase._create(self, id, **kw)
Exemplo n.º 8
0
 def _create(self, id, **kw):
     bus = kw.get('bus')
     if bus is None:
         raise TypeError('HWVendorID() did not get expected keyword '
                         'argument bus')
     vendor_id_for_bus = kw.get('vendor_id_for_bus')
     if vendor_id_for_bus is None:
         raise TypeError('HWVendorID() did not get expected keyword '
                         'argument vendor_id_for_bus')
     if not isValidVendorID(bus, vendor_id_for_bus):
         raise ParameterError(
             '%s is not a valid vendor ID for %s'
             % (repr(vendor_id_for_bus), bus.title))
     SQLBase._create(self, id, **kw)
Exemplo n.º 9
0
    def deviceDriverOwnersAffectedByBugs(
        self, bus=None, vendor_id=None, product_id=None, driver_name=None,
        package_name=None, bug_ids=None, bug_tags=None, affected_by_bug=False,
        subscribed_to_bug=False, user=None):
        """See `IHWSubmissionSet`."""
        store = IStore(HWSubmission)
        tables, clauses = make_submission_device_statistics_clause(
                bus, vendor_id, product_id, driver_name, package_name, False)
        tables.append(HWSubmission)
        clauses.append(HWSubmissionDevice.submission == HWSubmission.id)
        clauses.append(_userCanAccessSubmissionStormClause(user))

        if ((bug_ids is None or len(bug_ids) == 0) and
            (bug_tags is None or len(bug_tags) == 0)):
            raise ParameterError('bug_ids or bug_tags must be supplied.')

        tables.append(Bug)
        if bug_ids is not None and bug_ids is not []:
            clauses.append(Bug.id.is_in(bug_ids))

        if bug_tags is not None and bug_tags is not []:
            clauses.extend([
                Bug.id == BugTag.bugID, BugTag.tag.is_in(bug_tags)])
            tables.append(BugTag)

        # If we OR-combine the search for bug owners, subscribers
        # and affected people on SQL level, the query runs very slow.
        # So let's run the queries separately and join the results
        # on Python level.

        # This would be quicker still if we did it as a single query
        # using UNION.

        owner_query = Select(
            columns=[HWSubmission.ownerID], tables=tables,
            where=And(*(clauses + [Bug.ownerID == HWSubmission.ownerID])))
        user_ids = set(store.execute(owner_query))

        if subscribed_to_bug:
            subscriber_clauses = [
                BugSubscription.person_id == HWSubmission.ownerID,
                BugSubscription.bug == Bug.id,
                ]
            subscriber_query = Select(
                columns=[HWSubmission.ownerID],
                tables=tables + [BugSubscription],
                where=And(*(clauses + subscriber_clauses)))
            user_ids.update(store.execute(subscriber_query))

        if affected_by_bug:
            affected_clauses = [
                BugAffectsPerson.personID == HWSubmission.ownerID,
                BugAffectsPerson.bug == Bug.id,
                BugAffectsPerson.affected,
                ]
            affected_query = Select(
                columns=[HWSubmission.ownerID],
                tables=tables + [BugAffectsPerson],
                where=And(*(clauses + affected_clauses)))
            user_ids.update(store.execute(affected_query))

        # A "WHERE x IN (y, z...)" query needs at least one element
        # on the right side of IN.
        if len(user_ids) == 0:
            result = store.find(Person, False)
        else:
            user_ids = [row[0] for row in user_ids]
            result = store.find(Person, Person.id.is_in(user_ids))
        result.order_by(Person.display_name)
        return result