~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Julian Edwards
  • Date: 2011-05-27 22:39:18 UTC
  • mto: This revision was merged to the branch mainline in revision 13205.
  • Revision ID: julian.edwards@canonical.com-20110527223918-o4beocdx299c44lc
package copy job will now hold packages in UNAPPROVED per the copy policy

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
from lp.services.job.model.job import Job
39
39
from lp.services.job.runner import BaseRunnableJob
40
40
from lp.soyuz.adapters.overrides import FromExistingOverridePolicy
 
41
from lp.soyuz.adapters.copypolicy import InsecureCopyPolicy
41
42
from lp.soyuz.interfaces.archive import CannotCopy
42
43
from lp.soyuz.interfaces.packagecopyjob import (
43
44
    IPackageCopyJob,
239
240
                    "Destination pocket must be 'release' for a PPA.")
240
241
 
241
242
        source_packages = set()
 
243
        source_names = set()
242
244
        for name, version, source_package in self.source_packages:
243
245
            if source_package is None:
244
246
                raise CannotCopy(
245
247
                    "Package %r %r not found." % (name, version))
246
248
            else:
247
249
                source_packages.add(source_package)
 
250
                source_names.add(
 
251
                    source_package.sourcepackagerelease.sourcepackagename)
248
252
 
249
253
        override_policy = FromExistingOverridePolicy()
250
254
        ancestry = override_policy.calculateSourceOverrides(
251
255
            self.target_archive, self.target_distroseries,
252
 
            self.target_pocket, source_packages)
 
256
            self.target_pocket, source_names)
253
257
 
254
258
        # The assumption here is that we are currently using one package
255
259
        # per job right now to make it easier to show feedback to users
256
 
        # in the UI.  If/when that changes, this code needs to also
 
260
        # in the UI.  If/when that changes, this code also needs to
257
261
        # change.
258
 
        if len(ancestry) == 0:
259
 
            # There's no existing package with the same name so we poke
260
 
            # it in the NEW queue.
261
 
            # TODO We need to use InsecureCopyPolicy here but it needs
262
 
            # fixing so it doesn't require a PackageUpload.
 
262
        copy_policy = InsecureCopyPolicy()
 
263
        approve_new = copy_policy.autoApproveNew(
 
264
            self.target_archive, self.target_distroseries, self.target_pocket)
 
265
        if len(ancestry) == 0 and not approve_new:
 
266
            # There's no existing package with the same name and the
 
267
            # policy says unapproved, so we poke it in the NEW queue.
263
268
            self.suspend()
264
269
            pu = self.target_distroseries.createQueueEntry(
265
270
                pocket=self.target_pocket, changesfilename="changes",
269
274
            # when it has a package_copy_job.
270
275
            return
271
276
 
 
277
        # The package is not new (it has ancestry) so check the copy
 
278
        # policy for existing packages.
 
279
        approve_existing = copy_policy.autoApprove(
 
280
            self.target_archive, self.target_distroseries, self.target_pocket)
 
281
        if not approve_existing:
 
282
            pu = self.target_distroseries.createQueueEntry(
 
283
                pocket=self.target_pocket, changesfilename="changes",
 
284
                changesfilecontent="changes", archive=self.target_archive,
 
285
                package_copy_job=self.context)
 
286
            pu.setUnapproved()
 
287
            self.suspend()
 
288
            return
 
289
 
 
290
        # The package is free to go right in, so just copy it now.
272
291
        do_copy(
273
292
            sources=source_packages, archive=self.target_archive,
274
293
            series=self.target_distroseries, pocket=self.target_pocket,
281
300
        if len(source_packages) == 0:
282
301
            parts.append(" no packages (!)")
283
302
        else:
284
 
            # source_packages is 2-tuples so divide by 2 to get true
285
 
            # length.
286
 
            parts.append(" %d package(s)" % (len(source_packages)/2))
 
303
            parts.append(" %d package(s)" % len(source_packages))
287
304
        parts.append(
288
305
            " from %s/%s" % (
289
306
                self.source_archive.distribution.name,