~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-12-06 09:08:39 UTC
  • mfrom: (14421.2.8 sponsor-syncs-bug-827555)
  • Revision ID: launchpad@pqm.canonical.com-20111206090839-fm73xxdr08hyvasc
[r=benji][bug=827555] Make the package copier accept a "sponsored"
 Person which will be used as the SPPH.creator and From: address on
 announcement emails. Also expose the new parameter on
 IArchive.copyPackage[s]() on the API.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
from lp.registry.interfaces.distroseriesdifferencecomment import (
46
46
    IDistroSeriesDifferenceCommentSource,
47
47
    )
 
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)
237
238
 
238
239
    @classmethod
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."""
 
243
        if sponsored:
 
244
            sponsored_name = sponsored.name
 
245
        else:
 
246
            sponsored_name = None
241
247
        return {
242
248
            'target_pocket': target_pocket.value,
243
249
            'package_version': package_version,
244
250
            'include_binaries': bool(include_binaries),
 
251
            'sponsored': sponsored_name,
245
252
        }
246
253
 
247
254
    @classmethod
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,
 
259
               sponsored=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,
268
276
 
269
277
    @classmethod
270
278
    def _composeJobInsertionTuple(cls, target_distroseries, copy_policy,
271
 
                                  include_binaries, job_id, copy_task):
 
279
                                  include_binaries, job_id, copy_task,
 
280
                                  sponsored):
272
281
        """Create an SQL fragment for inserting a job into the database.
273
282
 
274
283
        :return: A string representing an SQL tuple containing initializers
283
292
            target_pocket,
284
293
        ) = copy_task
285
294
        metadata = cls._makeMetadata(
286
 
            target_pocket, package_version, include_binaries)
 
295
            target_pocket, package_version, include_binaries, sponsored)
287
296
        data = (
288
297
            cls.class_job_type, target_distroseries, copy_policy,
289
298
            source_archive, target_archive, package_name, job_id,
294
303
    @classmethod
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)
301
310
        job_contents = [
302
311
            cls._composeJobInsertionTuple(
303
312
                target_distroseries, copy_policy, include_binaries, job_id,
304
 
                task)
 
313
                task, sponsored)
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']
364
373
 
 
374
    @property
 
375
    def sponsored(self):
 
376
        name = self.metadata['sponsored']
 
377
        if name is None:
 
378
            return None
 
379
        return getUtility(IPersonSet).getByName(name)
 
380
 
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)
514
531
 
515
532
        # Add a PackageDiff for this new upload if it has ancestry.
516
533
        if ancestry is not None: