51
51
from lp.services.job.model.job import Job
52
52
from lp.services.job.runner import BaseRunnableJob
53
from lp.soyuz.adapters.copypolicy import InsecureCopyPolicy
54
53
from lp.soyuz.adapters.overrides import (
55
54
FromExistingOverridePolicy,
290
289
def getSourceOverride(self):
291
290
"""Fetch an `ISourceOverride` from the metadata."""
292
# There's only one package per job; although the schema allows
293
# multiple we're not using that.
294
291
name = self.package_name
295
292
component_name = self.metadata.get("component_override")
296
293
section_name = self.metadata.get("section_override")
297
294
source_package_name = getUtility(ISourcePackageNameSet)[name]
298
component = getUtility(IComponentSet)[component_name]
299
section = getUtility(ISectionSet)[section_name]
296
component = getUtility(IComponentSet)[component_name]
297
except NotFoundError:
300
section = getUtility(ISectionSet)[section_name]
301
except NotFoundError:
300
304
return SourceOverride(source_package_name, component, section)
302
306
def _checkPolicies(self, source_name):
308
312
self.target_archive, self.target_distroseries,
309
313
self.target_pocket, [source_name])
311
# TODO: this policy should come from the job itself, waiting on
312
# jtv to do the schema/model changes.
313
copy_policy = InsecureCopyPolicy()
314
approve_new = copy_policy.autoApproveNew(
315
self.target_archive, self.target_distroseries, self.target_pocket)
316
if len(ancestry) == 0 and not approve_new:
315
copy_policy = self.getPolicyImplementation()
317
if len(ancestry) == 0:
317
318
# We need to get the default overrides and put them in the
319
320
defaults = UnknownOverridePolicy().calculateSourceOverrides(
321
322
self.target_pocket, [source_name])
322
323
self.addSourceOverride(defaults[0])
324
# There's no existing package with the same name and the
325
# policy says unapproved, so we poke it in the NEW queue.
326
self._createPackageUpload()
327
raise SuspendJobException
325
approve_new = copy_policy.autoApproveNew(
326
self.target_archive, self.target_distroseries,
330
# There's no existing package with the same name and the
331
# policy says unapproved, so we poke it in the NEW queue.
332
self._createPackageUpload()
333
raise SuspendJobException
335
# Put the existing override in the metadata.
336
self.addSourceOverride(ancestry[0])
329
338
# The package is not new (it has ancestry) so check the copy
330
339
# policy for existing packages.
331
340
approve_existing = copy_policy.autoApprove(
332
341
self.target_archive, self.target_distroseries, self.target_pocket)
333
342
if not approve_existing:
334
# Put the existing override in the metadata.
335
self.addSourceOverride(ancestry[0])
336
343
self._createPackageUpload(unapproved=True)
337
344
raise SuspendJobException