~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-06-07 13:27:15 UTC
  • mto: This revision was merged to the branch mainline in revision 13205.
  • Revision ID: julian.edwards@canonical.com-20110607132715-3jl1ouyewf2qo22u
fix a bunch of post-merge test failures

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
    )
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,
56
55
    SourceOverride,
289
288
 
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]
 
295
        try:
 
296
            component = getUtility(IComponentSet)[component_name]
 
297
        except NotFoundError:
 
298
            component = None
 
299
        try:
 
300
            section = getUtility(ISectionSet)[section_name]
 
301
        except NotFoundError:
 
302
            section = None
 
303
 
300
304
        return SourceOverride(source_package_name, component, section)
301
305
 
302
306
    def _checkPolicies(self, source_name):
308
312
            self.target_archive, self.target_distroseries,
309
313
            self.target_pocket, [source_name])
310
314
 
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()
 
316
 
 
317
        if len(ancestry) == 0:
317
318
            # We need to get the default overrides and put them in the
318
319
            # metadata.
319
320
            defaults = UnknownOverridePolicy().calculateSourceOverrides(
321
322
                self.target_pocket, [source_name])
322
323
            self.addSourceOverride(defaults[0])
323
324
 
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,
 
327
                self.target_pocket)
 
328
 
 
329
            if not approve_new:
 
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
 
334
        else:
 
335
            # Put the existing override in the metadata.
 
336
            self.addSourceOverride(ancestry[0])
328
337
 
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
338
345