~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/model/distroseriesdifferencejob.py

Merge db-devel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
    implements,
15
15
    )
16
16
 
17
 
from canonical.launchpad.interfaces.lpstorm import IMasterStore
 
17
from canonical.launchpad.interfaces.lpstorm import (
 
18
    IMasterStore,
 
19
    IStore,
 
20
    )
18
21
from lp.registry.interfaces.distroseriesdifference import (
19
22
    IDistroSeriesDifferenceSource,
20
23
    )
 
24
from lp.registry.interfaces.distroseriesparent import IDistroSeriesParentSet
21
25
from lp.registry.interfaces.pocket import PackagePublishingPocket
22
26
from lp.registry.model.distroseriesdifference import DistroSeriesDifference
23
27
from lp.registry.model.sourcepackagename import SourcePackageName
92
96
    """
93
97
    if distroseries is None:
94
98
        return False
95
 
    previous_series = distroseries.previous_series
96
 
    if previous_series is None:
97
 
        return False
98
 
    if previous_series.distribution == distroseries.distribution:
99
 
        # Differences within a distribution are not tracked.
100
 
        return False
 
99
    dsp = getUtility(IDistroSeriesParentSet).getByDerivedSeries(
 
100
        distroseries)
 
101
    if dsp.count() == 0:
 
102
        return False
 
103
    for parent in dsp:
 
104
        if parent.parent_series.distribution == distroseries.distribution:
 
105
            # Differences within a distribution are not tracked.
 
106
            return False
101
107
    return find_waiting_jobs(distroseries, sourcepackagename).is_empty()
102
108
 
103
109
 
136
142
                jobs.append(create_job(relative, sourcepackagename))
137
143
        return jobs
138
144
 
 
145
    @classmethod
 
146
    def getPendingJobsForDifferences(cls, derived_series,
 
147
                                     distroseriesdifferences):
 
148
        """See `IDistroSeriesDifferenceJobSource`."""
 
149
        jobs = IStore(DistributionJob).find(
 
150
            DistributionJob,
 
151
            DistributionJob.job_type == cls.class_job_type,
 
152
            Job.id == DistributionJob.job_id,
 
153
            Job._status.is_in(Job.PENDING_STATUSES),
 
154
            DistributionJob.distroseries == derived_series)
 
155
 
 
156
        # XXX JeroenVermeulen 2011-05-26 bug=758906: Check for parent
 
157
        # series once it becomes available.
 
158
        keyed_dsds = dict(
 
159
            (dsd.source_package_name.id, dsd)
 
160
            for dsd in distroseriesdifferences)
 
161
        jobs_by_dsd = {}
 
162
        for job in jobs:
 
163
            dsd = keyed_dsds.get(job.metadata["sourcepackagename"])
 
164
            if dsd is not None:
 
165
                jobs_by_dsd.setdefault(dsd, []).append(cls(job))
 
166
        return jobs_by_dsd
 
167
 
139
168
    @property
140
169
    def sourcepackagename(self):
141
170
        return SourcePackageName.get(self.metadata['sourcepackagename'])
148
177
        in a packageset that the derived series also has.
149
178
        """
150
179
        derived_series = self.distroseries
151
 
        previous_series = derived_series.previous_series
 
180
        dsp = getUtility(IDistroSeriesParentSet).getByDerivedSeries(
 
181
            derived_series)
 
182
        parent_series = dsp[0].parent_series
152
183
        if has_package(derived_series, self.sourcepackagename):
153
184
            return True
154
 
        if not has_package(previous_series, self.sourcepackagename):
 
185
        if not has_package(parent_series, self.sourcepackagename):
155
186
            return True
156
187
        packagesetset = getUtility(IPackagesetSet)
157
 
        if packagesetset.getBySeries(previous_series).is_empty():
 
188
        if packagesetset.getBySeries(parent_series).is_empty():
158
189
            # Parent series does not have packagesets, as would be the
159
190
            # case for e.g. Debian.  In that case, don't filter.
160
191
            return True
161
192
        parent_sets = packagesetset.setsIncludingSource(
162
 
            self.sourcepackagename, distroseries=previous_series)
 
193
            self.sourcepackagename, distroseries=parent_series)
163
194
        for parent_set in parent_sets:
164
195
            for related_set in parent_set.relatedSets():
165
196
                if related_set.distroseries == derived_series: