48
48
FEATURE_FLAG_ENABLE_MODULE = u"soyuz.derived_series_jobs.enabled"
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:
58
parent_id = parent_series.id
60
54
'sourcepackagename': sourcepackagename.id,
61
'parent_series': parent_id,
55
'parent_series': parent_series.id,
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.
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`.
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,
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).
90
82
:param derived_series: A `DistroSeries` that is assumed to be derived
92
84
:param parent_series: A `DistroSeries` that is a parent of
94
:param archive: A `IArchive` where to find the source packages.
96
87
store = IStore(SourcePackageRelease)
97
88
source_package_releases = store.find(
134
125
return [job_id for job_id, in result]
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))
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)
165
151
for job in candidates
166
152
if job.metadata["parent_series"] == parent_series.id]
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?
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.
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:
182
166
dsp = getUtility(IDistroSeriesParentSet).getByDerivedSeries(
210
194
def createForPackagePublication(cls, derived_series, sourcepackagename,
211
pocket, parent_series=None):
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):
217
199
# -backports and -proposed are not really part of a standard
223
205
PackagePublishingPocket.PROPOSED):
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
211
for parent in parent_series:
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
218
for child in derived_series.getDerivedSeries():
220
child, sourcepackagename, derived_series):
221
jobs.append(create_job(
222
child, sourcepackagename, derived_series))
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):
238
create_multiple_jobs(derived_series, parent_series)
230
for parent_series in derived_series.getParentSeries():
231
create_multiple_jobs(derived_series, parent_series)
241
234
def getPendingJobsForDifferences(cls, derived_series,
248
241
Job._status.is_in(Job.PENDING_STATUSES),
249
242
DistributionJob.distroseries == derived_series)
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)
251
if job.metadata["parent_series"] not in parent_series_ids:
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))
272
267
def parent_series(self):
273
268
parent_id = self.metadata['parent_series']
275
# XXX JeroenVermeulen 2011-05-26 bug=758906: Make parent_series
276
# mandatory as part of multi-parent support.
278
269
return IStore(DistroSeries).get(DistroSeries, parent_id)
280
271
def passesPackagesetFilter(self):
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(
294
parent_series = dsp[0].parent_series
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:
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,
307
DistroSeriesDifference.parent_series_id == parent_id,
308
DistroSeriesDifference.source_package_name_id == spn_id)
331
309
return search.one()