def getMergeProposals(self, statuses=None, for_branches=None, target_branch=None, prerequisite_branch=None, merged_revnos=None, merged_revision=None, eager_load=False): """See `IBranchCollection`.""" if for_branches is not None and not for_branches: # We have an empty branches list, so we can shortcut. return EmptyResultSet() elif merged_revnos is not None and not merged_revnos: # We have an empty revnos list, so we can shortcut. return EmptyResultSet() elif (self._asymmetric_filter_expressions or for_branches is not None or target_branch is not None or prerequisite_branch is not None or merged_revnos is not None or merged_revision is not None): return self._naiveGetMergeProposals(statuses, for_branches, target_branch, prerequisite_branch, merged_revnos, merged_revision, eager_load=eager_load) else: # When examining merge proposals in a scope, this is a moderately # effective set of constrained queries. It is not effective when # unscoped or when tight constraints on branches are present. return self._scopedGetMergeProposals(statuses, eager_load=eager_load)
def getNotNewByNames(self, name_ids, distroseries, archive_ids): """See `IBinaryPackageNameSet`.""" # Circular imports. from lp.soyuz.model.distroarchseries import DistroArchSeries from lp.soyuz.model.publishing import BinaryPackagePublishingHistory if len(name_ids) == 0: return EmptyResultSet() return IStore(BinaryPackagePublishingHistory).using( BinaryPackagePublishingHistory, Join( BinaryPackageName, BinaryPackagePublishingHistory.binarypackagenameID == BinaryPackageName.id), Join( DistroArchSeries, BinaryPackagePublishingHistory.distroarchseriesID == DistroArchSeries.id)).find( BinaryPackageName, DistroArchSeries.distroseries == distroseries, BinaryPackagePublishingHistory.status.is_in( active_publishing_status), BinaryPackagePublishingHistory.archiveID.is_in( archive_ids), BinaryPackagePublishingHistory.binarypackagenameID.is_in( name_ids)).config(distinct=True)
def getDiffsToReleases(self, sprs, preload_for_display=False): """See `IPackageDiffSet`.""" from lp.registry.model.distribution import Distribution from lp.soyuz.model.archive import Archive from lp.soyuz.model.sourcepackagerelease import SourcePackageRelease if len(sprs) == 0: return EmptyResultSet() spr_ids = [spr.id for spr in sprs] result = IStore(PackageDiff).find( PackageDiff, PackageDiff.to_sourceID.is_in(spr_ids)) result.order_by(PackageDiff.to_sourceID, Desc(PackageDiff.date_requested)) def preload_hook(rows): lfas = load(LibraryFileAlias, (pd.diff_contentID for pd in rows)) load(LibraryFileContent, (lfa.contentID for lfa in lfas)) sprs = load( SourcePackageRelease, itertools.chain.from_iterable( (pd.from_sourceID, pd.to_sourceID) for pd in rows)) archives = load(Archive, (spr.upload_archiveID for spr in sprs)) load(Distribution, (a.distributionID for a in archives)) if preload_for_display: return DecoratedResultSet(result, pre_iter_hook=preload_hook) else: return result
def test_StormRangeFactory__EmptyResultSet(self): # It is possible to create StormRangeFactory instances for # EmptyResultSets, resultset = EmptyResultSet() range_factory = StormRangeFactory(resultset) self.assertEqual(0, range_factory.rough_length) self.assertEmptyResultSetsWorking(range_factory)
def query_structural_subscriptions( what, bug, bugtasks, level, exclude=None): """Query into structural subscriptions for a given bug. :param what: The fields to fetch. Choose from `Person`, `StructuralSubscription`, `BugSubscriptionFilter`, or a combo. :param bug: An `IBug` :param bugtasks: An iterable of `IBugTask`. :param level: A level from `BugNotificationLevel`. Filters below this level will be excluded. :param exclude: `Person`s to exclude (e.g. direct subscribers). """ from lp.registry.model.person import Person # Circular. filter_id_query = ( _get_structural_subscription_filter_id_query( bug, bugtasks, level, exclude)) if not filter_id_query: return EmptyResultSet() source = IStore(StructuralSubscription).using( StructuralSubscription, Join(BugSubscriptionFilter, BugSubscriptionFilter.structural_subscription_id == StructuralSubscription.id), Join(Person, Person.id == StructuralSubscription.subscriberID)) conditions = In( BugSubscriptionFilter.id, filter_id_query) return source.find(what, conditions)
def getByBuildFarmJobs(cls, build_farm_jobs): """See `ISpecificBuildFarmJobSource`.""" if len(build_farm_jobs) == 0: return EmptyResultSet() rows = Store.of(build_farm_jobs[0]).find( cls, cls.build_farm_job_id.is_in(bfj.id for bfj in build_farm_jobs)) return DecoratedResultSet(rows, pre_iter_hook=cls.preloadBuildsData)
def builds(self): """See `ISnapRequestBuildsJob`.""" build_ids = self.metadata.get("builds") if build_ids: return IStore(SnapBuild).find(SnapBuild, SnapBuild.id.is_in(build_ids)) else: return EmptyResultSet()
def emptySelectResults(self): """Return a SelectResults object without any elements. This is to be used when no search string is given to the search() method of subclasses, in order to be consistent and always return a SelectResults object. """ return EmptyResultSet()
def getFilesForReleases(self, releases): """See `IProductReleaseSet`.""" releases = list(releases) if len(releases) == 0: return EmptyResultSet() return ProductReleaseFile.select( """ProductReleaseFile.productrelease IN %s""" % (sqlvalues([release.id for release in releases])), orderBy='-date_uploaded', prejoins=['libraryfile', 'libraryfile.content', 'productrelease'])
def getBinariesForOverrides(self, distroseries, pocket): """Fetch override information about all published binaries. The override information consists of tuples with 'binaryname', 'component', 'section', 'architecture' and 'priority' strings, 'binpackageformat' enum, 'phased_update_percentage' integer, in this order. :param distroseries: target `IDistroSeries` :param pocket: target `PackagePublishingPocket` :return: a `ResultSet` with the binary override information tuples """ origins = ( BinaryPackagePublishingHistory, Join(Component, Component.id == BinaryPackagePublishingHistory.componentID), Join(Section, Section.id == BinaryPackagePublishingHistory.sectionID), Join( BinaryPackageRelease, BinaryPackageRelease.id == BinaryPackagePublishingHistory.binarypackagereleaseID), Join( BinaryPackageName, BinaryPackageName.id == BinaryPackageRelease.binarypackagenameID), Join( DistroArchSeries, DistroArchSeries.id == BinaryPackagePublishingHistory.distroarchseriesID), ) architectures_ids = [arch.id for arch in distroseries.architectures] if len(architectures_ids) == 0: return EmptyResultSet() conditions = [ BinaryPackagePublishingHistory.archive == self.publisher.archive, BinaryPackagePublishingHistory.distroarchseriesID.is_in( architectures_ids), BinaryPackagePublishingHistory.pocket == pocket, BinaryPackagePublishingHistory.status == PackagePublishingStatus.PUBLISHED, ] if not self.publisher.archive.publish_debug_symbols: conditions.append(BinaryPackageRelease.binpackageformat != BinaryPackageFormat.DDEB) result_set = IStore(BinaryPackageName).using(*origins).find( (BinaryPackageName.name, Component.name, Section.name, DistroArchSeries.architecturetag, BinaryPackagePublishingHistory.priority, BinaryPackageRelease.binpackageformat, BinaryPackagePublishingHistory.phased_update_percentage), *conditions) return result_set.order_by(Desc(BinaryPackagePublishingHistory.id))
def getReleasesForSeries(self, series): """See `IProductReleaseSet`.""" # Local import of Milestone to avoid import loop. from lp.registry.model.milestone import Milestone if len(list(series)) == 0: return EmptyResultSet() series_ids = [s.id for s in series] return IStore(ProductRelease).find( ProductRelease, And(ProductRelease.milestone == Milestone.id), Milestone.productseriesID.is_in(series_ids)).order_by( Desc(ProductRelease.datereleased))
def getNonActiveSubscribers(self): """See `IArchiveSubscriber`.""" store = Store.of(self) if self.subscriber.is_team: # We get all the people who already have active tokens for # this archive (for example, through separate subscriptions). auth_token = LeftJoin( ArchiveAuthToken, And(ArchiveAuthToken.person_id == Person.id, ArchiveAuthToken.archive_id == self.archive_id, ArchiveAuthToken.date_deactivated == None)) team_participation = Join(TeamParticipation, TeamParticipation.personID == Person.id) # Only return people with preferred email address set. preferred_email = Join(EmailAddress, EmailAddress.personID == Person.id) # We want to get all participants who are themselves # individuals, not teams: non_active_subscribers = store.using( Person, team_participation, preferred_email, auth_token).find( (Person, EmailAddress), EmailAddress.status == EmailAddressStatus.PREFERRED, TeamParticipation.teamID == self.subscriber_id, Person.teamowner == None, # There is no existing archive auth token. ArchiveAuthToken.person_id == None) non_active_subscribers.order_by(Person.name) return non_active_subscribers else: # Subscriber is not a team. token_set = getUtility(IArchiveAuthTokenSet) if token_set.getActiveTokenForArchiveAndPerson( self.archive, self.subscriber) is not None: # There are active tokens, so return an empty result # set. return EmptyResultSet() # Otherwise return a result set containing only the # subscriber and their preferred email address. return store.find( (Person, EmailAddress), Person.id == self.subscriber_id, EmailAddress.personID == Person.id, EmailAddress.status == EmailAddressStatus.PREFERRED)
def getBuildRecords(self, build_state=None, name=None, pocket=None, arch_tag=None, user=None, binary_only=True): """See IHasBuildRecords""" # Ignore "user", since it would not make any difference to the # records returned here (private builds are only in PPA right # now). # Ignore "binary_only" as for a distro arch series it is only # the binaries that are relevant. # For consistency we return an empty resultset if arch_tag # is provided but doesn't match our architecture. if arch_tag is not None and arch_tag != self.architecturetag: return EmptyResultSet() # Use the facility provided by IBinaryPackageBuildSet to # retrieve the records. return getUtility(IBinaryPackageBuildSet).getBuildsForDistro( self, build_state, name, pocket)
def get_structural_subscriptions_for_bug(bug, person=None): """Find the structural subscriptions to the bug. If `person` is provided, only subscriptions that affect the person, because of personal or team memberships, are included. """ # This is here because of a circular import. from lp.registry.model.person import Person bugtasks = bug.bugtasks if not bugtasks: return EmptyResultSet() conditions = [] if person is not None: conditions.extend([ StructuralSubscription.subscriber == Person.id, TeamParticipation.personID == person.id, TeamParticipation.teamID == Person.id]) return _get_structural_subscriptions( StructuralSubscription, get_structural_subscription_targets(bugtasks), *conditions)
class TestSQLObjectResultSet(object): _result_set = EmptyResultSet()