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 (
239
240
"Destination pocket must be 'release' for a PPA.")
241
242
source_packages = 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))
247
249
source_packages.add(source_package)
251
source_package.sourcepackagerelease.sourcepackagename)
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)
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
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.
264
269
pu = self.target_distroseries.createQueueEntry(
265
270
pocket=self.target_pocket, changesfilename="changes",
269
274
# when it has a package_copy_job.
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)
290
# The package is free to go right in, so just copy it now.
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 (!)")
284
# source_packages is 2-tuples so divide by 2 to get true
286
parts.append(" %d package(s)" % (len(source_packages)/2))
303
parts.append(" %d package(s)" % len(source_packages))
288
305
" from %s/%s" % (
289
306
self.source_archive.distribution.name,