~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-06-25 08:55:37 UTC
  • mfrom: (13287.1.8 bug-800652)
  • Revision ID: launchpad@pqm.canonical.com-20110625085537-moikyoo2pe98zs7r
[r=jcsackett, julian-edwards][bug=800634,
        800652] Enable and display overrides on sync package uploads.

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
from lp.services.mail.signedmessage import strip_pgp_signature
67
67
from lp.services.propertycache import cachedproperty
68
68
from lp.soyuz.adapters.notification import notify
 
69
from lp.soyuz.adapters.overrides import SourceOverride
69
70
from lp.soyuz.enums import (
70
71
    PackageUploadCustomFormat,
71
72
    PackageUploadStatus,
72
73
    )
73
74
from lp.soyuz.interfaces.archive import MAIN_ARCHIVE_PURPOSES
 
75
from lp.soyuz.interfaces.packagecopyjob import IPackageCopyJobSource
74
76
from lp.soyuz.interfaces.publishing import (
75
77
    IPublishingSet,
76
78
    ISourcePackagePublishingHistory,
467
469
        self._closeBugs(changesfile_path, logger)
468
470
        self._giveKarma()
469
471
 
470
 
    def acceptFromQueue(self, logger=None, dry_run=False):
471
 
        """See `IPackageUpload`."""
472
 
        assert not self.is_delayed_copy, 'Cannot process delayed copies.'
473
 
 
474
 
        if self.package_copy_job is not None:
475
 
            if self.status == PackageUploadStatus.REJECTED:
476
 
                raise QueueInconsistentStateError(
477
 
                    "Can't resurrect rejected syncs")
478
 
            # Circular imports :(
479
 
            from lp.soyuz.model.packagecopyjob import PlainPackageCopyJob
480
 
            # Release the job hounds, Smithers.
481
 
            self.setAccepted()
482
 
            job = PlainPackageCopyJob.get(self.package_copy_job_id)
483
 
            job.resume()
484
 
            # The copy job will send emails as appropriate.  We don't
485
 
            # need to worry about closing bugs from syncs, although we
486
 
            # should probably give karma but that needs more work to
487
 
            # fix here.
488
 
            return
 
472
    def _acceptSyncFromQueue(self):
 
473
        """Accept a sync upload from the queue."""
 
474
        # Circular imports :(
 
475
        from lp.soyuz.model.packagecopyjob import PlainPackageCopyJob
 
476
 
 
477
        assert self.package_copy_job is not None, (
 
478
            "This method is for copy-job uploads only.")
 
479
        assert not self.is_delayed_copy, (
 
480
            "This method is not for delayed copies.")
 
481
 
 
482
        if self.status == PackageUploadStatus.REJECTED:
 
483
            raise QueueInconsistentStateError(
 
484
                "Can't resurrect rejected syncs")
 
485
 
 
486
        # Release the job hounds, Smithers.
 
487
        self.setAccepted()
 
488
        job = PlainPackageCopyJob.get(self.package_copy_job_id)
 
489
        job.resume()
 
490
        # The copy job will send emails as appropriate.  We don't
 
491
        # need to worry about closing bugs from syncs, although we
 
492
        # should probably give karma but that needs more work to
 
493
        # fix here.
 
494
 
 
495
    def _acceptNonSyncFromQueue(self, logger=None, dry_run=False):
 
496
        """Accept a "regular" upload from the queue.
 
497
 
 
498
        This is the normal case, for uploads that are not delayed and are not
 
499
        attached to package copy jobs.
 
500
        """
 
501
        assert self.package_copy_job is None, (
 
502
            "This method is not for copy-job uploads.")
 
503
        assert not self.is_delayed_copy, (
 
504
            "This method is not for delayed copies.")
489
505
 
490
506
        self.setAccepted()
491
507
 
515
531
        # Give some karma!
516
532
        self._giveKarma()
517
533
 
 
534
    def acceptFromQueue(self, logger=None, dry_run=False):
 
535
        """See `IPackageUpload`."""
 
536
        assert not self.is_delayed_copy, 'Cannot process delayed copies.'
 
537
 
 
538
        if self.package_copy_job is None:
 
539
            self._acceptNonSyncFromQueue(logger, dry_run)
 
540
        else:
 
541
            self._acceptSyncFromQueue()
 
542
 
518
543
    def acceptFromCopy(self):
519
544
        """See `IPackageUpload`."""
520
545
        assert self.is_delayed_copy, 'Can only process delayed-copies.'
615
640
    def package_version(self):
616
641
        """See `IPackageUpload`."""
617
642
        if self.package_copy_job_id is not None:
618
 
            return self.package_copy_job.metadata["package_version"]
 
643
            return self.package_copy_job.package_version
619
644
        elif self.sourcepackagerelease is not None:
620
645
            return self.sourcepackagerelease.version
621
646
        else:
625
650
    def component_name(self):
626
651
        """See `IPackageUpload`."""
627
652
        if self.package_copy_job_id is not None:
628
 
            return self.package_copy_job.metadata["component_override"]
629
 
        elif self.sourcepackagerelease is not None:
 
653
            return self.package_copy_job.component_name
 
654
        elif self.contains_source:
630
655
            return self.sourcepackagerelease.component.name
631
656
        else:
632
657
            return None
635
660
    def section_name(self):
636
661
        """See `IPackageUpload`."""
637
662
        if self.package_copy_job_id is not None:
638
 
            return self.package_copy_job.metadata["section_override"]
639
 
        elif self.sourcepackagerelease is not None:
 
663
            return self.package_copy_job.section_name
 
664
        elif self.contains_source:
640
665
            return self.sourcepackagerelease.section.name
641
666
        else:
642
667
            return None
853
878
                    existing_components.add(binary.component)
854
879
        return existing_components
855
880
 
856
 
    def overrideSource(self, new_component, new_section, allowed_components):
 
881
    @cachedproperty
 
882
    def concrete_package_copy_job(self):
857
883
        """See `IPackageUpload`."""
858
 
        if new_component is None and new_section is None:
859
 
            # Nothing needs overriding, bail out.
860
 
            return False
861
 
 
862
 
        if self.package_copy_job is not None:
863
 
            # We just need to add the required component/section to the
864
 
            # job metadata.
865
 
            extra_data = {}
866
 
            if new_component is not None:
867
 
                extra_data['component_override'] = new_component.name
868
 
            if new_section is not None:
869
 
                extra_data['section_override'] = new_section.name
870
 
            self.package_copy_job.extendMetadata(extra_data)
871
 
            return
872
 
 
873
 
        if not self.contains_source:
874
 
            return False
 
884
        return getUtility(IPackageCopyJobSource).wrap(self.package_copy_job)
 
885
 
 
886
    def _overrideSyncSource(self, new_component, new_section,
 
887
                            allowed_components):
 
888
        """Override source on the upload's `PackageCopyJob`, if any."""
 
889
        if self.package_copy_job is None:
 
890
            return False
 
891
 
 
892
        copy_job = self.concrete_package_copy_job
 
893
        allowed_component_names = [
 
894
            component.name for component in allowed_components]
 
895
        if copy_job.component_name not in allowed_component_names:
 
896
            raise QueueInconsistentStateError(
 
897
                "No rights to override from %s" % copy_job.component_name)
 
898
        copy_job.addSourceOverride(SourceOverride(
 
899
            copy_job.package_name, new_component, new_section))
 
900
 
 
901
        return True
 
902
 
 
903
    def _overrideNonSyncSource(self, new_component, new_section,
 
904
                               allowed_components):
 
905
        """Override sources on a source upload."""
 
906
        made_changes = False
875
907
 
876
908
        for source in self.sources:
877
 
            if (new_component not in allowed_components or
878
 
                source.sourcepackagerelease.component not in
879
 
                    allowed_components):
880
 
                # The old or the new component is not in the list of
881
 
                # allowed components to override.
 
909
            old_component = source.sourcepackagerelease.component
 
910
            if old_component not in allowed_components:
 
911
                # The old component is not in the list of allowed components
 
912
                # to override.
882
913
                raise QueueInconsistentStateError(
883
 
                    "No rights to override from %s to %s" % (
884
 
                        source.sourcepackagerelease.component.name,
885
 
                        new_component.name))
 
914
                    "No rights to override from %s" % old_component.name)
886
915
            source.sourcepackagerelease.override(
887
916
                component=new_component, section=new_section)
 
917
            made_changes = True
888
918
 
889
919
        # We override our own archive too, as it is used to create
890
920
        # the SPPH during publish().
891
921
        self.archive = self.distroseries.distribution.getArchiveByComponent(
892
922
            new_component.name)
893
923
 
894
 
        return True
 
924
        return made_changes
 
925
 
 
926
    def overrideSource(self, new_component, new_section, allowed_components):
 
927
        """See `IPackageUpload`."""
 
928
        if new_component is None and new_section is None:
 
929
            # Nothing needs overriding, bail out.
 
930
            return False
 
931
 
 
932
        if new_component not in allowed_components:
 
933
            raise QueueInconsistentStateError(
 
934
                "No rights to override to %s" % new_component.name)
 
935
 
 
936
        return (
 
937
            self._overrideSyncSource(
 
938
                new_component, new_section, allowed_components) or
 
939
            self._overrideNonSyncSource(
 
940
                new_component, new_section, allowed_components))
895
941
 
896
942
    def overrideBinaries(self, new_component, new_section, new_priority,
897
943
                         allowed_components):
904
950
            # Nothing needs overriding, bail out.
905
951
            return False
906
952
 
 
953
        if new_component not in allowed_components:
 
954
            raise QueueInconsistentStateError(
 
955
                "No rights to override to %s" % new_component.name)
 
956
 
907
957
        for build in self.builds:
908
958
            for binarypackage in build.build.binarypackages:
909
 
                if (new_component not in allowed_components or
910
 
                    binarypackage.component not in allowed_components):
 
959
                if binarypackage.component not in allowed_components:
911
960
                    # The old or the new component is not in the list of
912
961
                    # allowed components to override.
913
962
                    raise QueueInconsistentStateError(
914
 
                        "No rights to override from %s to %s" % (
915
 
                            binarypackage.component.name,
916
 
                            new_component.name))
 
963
                        "No rights to override from %s" % (
 
964
                            binarypackage.component.name))
917
965
                binarypackage.override(
918
966
                    component=new_component,
919
967
                    section=new_section,