~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Benji York
  • Date: 2011-08-01 12:51:12 UTC
  • mfrom: (13572 devel)
  • mto: This revision was merged to the branch mainline in revision 13573.
  • Revision ID: benji.york@canonical.com-20110801125112-a4euql70924suzb6
mergeĀ fromĀ devel

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
FEATURE_FLAG_ENABLE_MODULE = u"soyuz.derived_series_jobs.enabled"
49
49
 
50
50
 
51
 
def make_metadata(sourcepackagename, parent_series=None):
 
51
def make_metadata(sourcepackagename, parent_series):
52
52
    """Return JSON metadata for a job on `sourcepackagename`."""
53
 
    # XXX JeroenVermeulen 2011-05-26 bug=758906: Make parent_series
54
 
    # mandatory as part of multi-parent support.
55
 
    if parent_series is None:
56
 
        parent_id = None
57
 
    else:
58
 
        parent_id = parent_series.id
59
53
    return {
60
54
        'sourcepackagename': sourcepackagename.id,
61
 
        'parent_series': parent_id,
 
55
        'parent_series': parent_series.id,
62
56
    }
63
57
 
64
58
 
65
 
def create_job(derived_series, sourcepackagename, parent_series=None):
 
59
def create_job(derived_series, sourcepackagename, parent_series):
66
60
    """Create a `DistroSeriesDifferenceJob` for a given source package.
67
61
 
68
62
    :param derived_series: A `DistroSeries` that is assumed to be derived
73
67
        `derived_series`.  The difference is between the versions of
74
68
        `sourcepackagename` in `parent_series` and `derived_series`.
75
69
    """
76
 
    # XXX JeroenVermeulen 2011-05-26 bug=758906: Make parent_series
77
 
    # mandatory as part of multi-parent support.
78
70
    job = DistributionJob(
79
71
        distribution=derived_series.distribution, distroseries=derived_series,
80
72
        job_type=DistributionJobType.DISTROSERIESDIFFERENCE,
85
77
 
86
78
def create_multiple_jobs(derived_series, parent_series):
87
79
    """Create a `DistroSeriesDifferenceJob` for all the source packages in
88
 
    archive (optionally limited to the sourcepackagenames passed).
 
80
    archive.
89
81
 
90
82
    :param derived_series: A `DistroSeries` that is assumed to be derived
91
83
        from another one.
92
84
    :param parent_series: A `DistroSeries` that is a parent of
93
85
        `derived_series`.
94
 
    :param archive: A `IArchive` where to find the source packages.
95
86
    """
96
87
    store = IStore(SourcePackageRelease)
97
88
    source_package_releases = store.find(
134
125
    return [job_id for job_id, in result]
135
126
 
136
127
 
137
 
def find_waiting_jobs(derived_series, sourcepackagename, parent_series=None):
 
128
def find_waiting_jobs(derived_series, sourcepackagename, parent_series):
138
129
    """Look for pending `DistroSeriesDifference` jobs on a package."""
139
130
    # Look for identical pending jobs.  This compares directly on
140
131
    # the metadata string.  It's fragile, but this is only an
155
146
        DistributionJob._json_data == json_metadata,
156
147
        DistributionJob.job_id.is_in(Job.ready_jobs))
157
148
 
158
 
    # XXX JeroenVermeulen 2011-05-26 bug=758906: Make parent_series
159
 
    # mandatory as part of multi-parent support.
160
 
    if parent_series is None:
161
 
        return list(candidates)
162
 
 
163
149
    return [
164
150
        job
165
151
        for job in candidates
166
152
            if job.metadata["parent_series"] == parent_series.id]
167
153
 
168
154
 
169
 
def may_require_job(derived_series, sourcepackagename, parent_series=None):
 
155
def may_require_job(derived_series, sourcepackagename, parent_series):
170
156
    """Might publishing this package require a new job?
171
157
 
172
158
    Use this to determine whether to create a new
175
161
    runner some unnecessary work, but we don't expect a bit of
176
162
    unnecessary work to be a big problem.
177
163
    """
178
 
    # XXX JeroenVermeulen 2011-05-26 bug=758906: Make parent_series
179
 
    # mandatory as part of multi-parent support.
180
164
    if derived_series is None:
181
165
        return False
182
166
    dsp = getUtility(IDistroSeriesParentSet).getByDerivedSeries(
208
192
 
209
193
    @classmethod
210
194
    def createForPackagePublication(cls, derived_series, sourcepackagename,
211
 
                                    pocket, parent_series=None):
 
195
                                    pocket):
212
196
        """See `IDistroSeriesDifferenceJobSource`."""
213
 
        # XXX JeroenVermeulen 2011-05-26 bug=758906: Make parent_series
214
 
        # mandatory as part of multi-parent support.
215
197
        if not getFeatureFlag(FEATURE_FLAG_ENABLE_MODULE):
216
198
            return
217
199
        # -backports and -proposed are not really part of a standard
223
205
            PackagePublishingPocket.PROPOSED):
224
206
            return
225
207
        jobs = []
226
 
        children = list(derived_series.getDerivedSeries())
227
 
        for relative in children + [derived_series]:
228
 
            if may_require_job(relative, sourcepackagename, parent_series):
229
 
                jobs.append(create_job(
230
 
                    relative, sourcepackagename, parent_series))
 
208
        parent_series = derived_series.getParentSeries()
 
209
        # Create jobs for DSDs between the derived_series and its
 
210
        # parents.
 
211
        for parent in parent_series:
 
212
            if may_require_job(
 
213
                derived_series, sourcepackagename, parent):
 
214
                jobs.append(create_job(
 
215
                    derived_series, sourcepackagename, parent))
 
216
        # Create jobs for DSDs between the derived_series and its
 
217
        # children.
 
218
        for child in derived_series.getDerivedSeries():
 
219
            if may_require_job(
 
220
                child, sourcepackagename, derived_series):
 
221
                jobs.append(create_job(
 
222
                    child, sourcepackagename, derived_series))
231
223
        return jobs
232
224
 
233
225
    @classmethod
234
 
    def massCreateForSeries(cls, derived_series, parent_series):
 
226
    def massCreateForSeries(cls, derived_series):
235
227
        """See `IDistroSeriesDifferenceJobSource`."""
236
228
        if not getFeatureFlag(FEATURE_FLAG_ENABLE_MODULE):
237
229
            return
238
 
        create_multiple_jobs(derived_series, parent_series)
 
230
        for parent_series in derived_series.getParentSeries():
 
231
            create_multiple_jobs(derived_series, parent_series)
239
232
 
240
233
    @classmethod
241
234
    def getPendingJobsForDifferences(cls, derived_series,
248
241
            Job._status.is_in(Job.PENDING_STATUSES),
249
242
            DistributionJob.distroseries == derived_series)
250
243
 
251
 
        # XXX JeroenVermeulen 2011-05-26 bug=758906: Check for parent
252
 
        # series once it becomes available.
 
244
        parent_series_ids = set(
 
245
            dsd.parent_series.id for dsd in distroseriesdifferences)
253
246
        keyed_dsds = dict(
254
247
            (dsd.source_package_name.id, dsd)
255
248
            for dsd in distroseriesdifferences)
256
249
        jobs_by_dsd = {}
257
250
        for job in jobs:
 
251
            if job.metadata["parent_series"] not in parent_series_ids:
 
252
                continue
258
253
            dsd = keyed_dsds.get(job.metadata["sourcepackagename"])
259
254
            if dsd is not None:
260
255
                jobs_by_dsd.setdefault(dsd, []).append(cls(job))
271
266
    @property
272
267
    def parent_series(self):
273
268
        parent_id = self.metadata['parent_series']
274
 
        if not parent_id:
275
 
            # XXX JeroenVermeulen 2011-05-26 bug=758906: Make parent_series
276
 
            # mandatory as part of multi-parent support.
277
 
            return None
278
269
        return IStore(DistroSeries).get(DistroSeries, parent_id)
279
270
 
280
271
    def passesPackagesetFilter(self):
286
277
        """
287
278
        derived_series = self.derived_series
288
279
        parent_series = self.parent_series
289
 
        # XXX JeroenVermeulen 2011-05-26 bug=758906: Make parent_series
290
 
        # mandatory as part of multi-parent support.
291
 
        if parent_series is None:
292
 
            dsp = getUtility(IDistroSeriesParentSet).getByDerivedSeries(
293
 
                derived_series)
294
 
            parent_series = dsp[0].parent_series
295
280
 
296
281
        sourcepackagename = self.sourcepackagename
297
282
        if has_package(derived_series, sourcepackagename):
316
301
        spn_id = self.metadata["sourcepackagename"]
317
302
        parent_id = self.metadata["parent_series"]
318
303
        store = IMasterStore(DistroSeriesDifference)
319
 
        # XXX JeroenVermeulen 2011-05-26 bug=758906: Make parent_series
320
 
        # mandatory as part of multi-parent support.
321
 
        if parent_id is None:
322
 
            match_parent = True
323
 
        else:
324
 
            match_parent = (
325
 
                DistroSeriesDifference.parent_series_id == parent_id)
326
304
        search = store.find(
327
305
            DistroSeriesDifference,
328
306
            DistroSeriesDifference.derived_series == self.derived_series,
329
 
            DistroSeriesDifference.source_package_name_id == spn_id,
330
 
            match_parent)
 
307
            DistroSeriesDifference.parent_series_id == parent_id,
 
308
            DistroSeriesDifference.source_package_name_id == spn_id)
331
309
        return search.one()
332
310
 
333
311
    def run(self):