45
45
from lp.registry.interfaces.distroseriesdifferencecomment import (
46
46
IDistroSeriesDifferenceCommentSource,
48
from lp.registry.interfaces.person import IPersonSet
48
49
from lp.registry.interfaces.pocket import PackagePublishingPocket
49
50
from lp.registry.interfaces.sourcepackagename import ISourcePackageNameSet
50
51
from lp.registry.model.distroseries import DistroSeries
236
237
classProvides(IPlainPackageCopyJobSource)
239
def _makeMetadata(cls, target_pocket, package_version, include_binaries):
240
def _makeMetadata(cls, target_pocket, package_version,
241
include_binaries, sponsored=None):
240
242
"""Produce a metadata dict for this job."""
244
sponsored_name = sponsored.name
246
sponsored_name = None
242
248
'target_pocket': target_pocket.value,
243
249
'package_version': package_version,
244
250
'include_binaries': bool(include_binaries),
251
'sponsored': sponsored_name,
248
255
def create(cls, package_name, source_archive,
249
256
target_archive, target_distroseries, target_pocket,
250
257
include_binaries=False, package_version=None,
251
copy_policy=PackageCopyPolicy.INSECURE, requester=None):
258
copy_policy=PackageCopyPolicy.INSECURE, requester=None,
252
260
"""See `IPlainPackageCopyJobSource`."""
253
261
assert package_version is not None, "No package version specified."
254
262
assert requester is not None, "No requester specified."
255
263
metadata = cls._makeMetadata(
256
target_pocket, package_version, include_binaries)
264
target_pocket, package_version, include_binaries, sponsored)
257
265
job = PackageCopyJob(
258
266
job_type=cls.class_job_type,
259
267
source_archive=source_archive,
270
278
def _composeJobInsertionTuple(cls, target_distroseries, copy_policy,
271
include_binaries, job_id, copy_task):
279
include_binaries, job_id, copy_task,
272
281
"""Create an SQL fragment for inserting a job into the database.
274
283
:return: A string representing an SQL tuple containing initializers
285
294
metadata = cls._makeMetadata(
286
target_pocket, package_version, include_binaries)
295
target_pocket, package_version, include_binaries, sponsored)
288
297
cls.class_job_type, target_distroseries, copy_policy,
289
298
source_archive, target_archive, package_name, job_id,
295
304
def createMultiple(cls, target_distroseries, copy_tasks, requester,
296
305
copy_policy=PackageCopyPolicy.INSECURE,
297
include_binaries=False):
306
include_binaries=False, sponsored=None):
298
307
"""See `IPlainPackageCopyJobSource`."""
299
308
store = IMasterStore(Job)
300
309
job_ids = Job.createMultiple(store, len(copy_tasks), requester)
302
311
cls._composeJobInsertionTuple(
303
312
target_distroseries, copy_policy, include_binaries, job_id,
305
314
for job_id, task in zip(job_ids, copy_tasks)]
306
315
result = store.execute("""
307
316
INSERT INTO PackageCopyJob (
362
371
def include_binaries(self):
363
372
return self.metadata['include_binaries']
376
name = self.metadata['sponsored']
379
return getUtility(IPersonSet).getByName(name)
365
381
def _createPackageUpload(self, unapproved=False):
366
382
pu = self.target_distroseries.createQueueEntry(
367
383
pocket=self.target_pocket, archive=self.target_archive,
510
526
series=self.target_distroseries, pocket=self.target_pocket,
511
527
include_binaries=self.include_binaries, check_permissions=True,
512
528
person=self.requester, overrides=[override],
513
send_email=send_email, announce_from_person=self.requester)
529
send_email=send_email, announce_from_person=self.requester,
530
sponsored=self.sponsored)
515
532
# Add a PackageDiff for this new upload if it has ancestry.
516
533
if ancestry is not None: