~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/adapters/overrides.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-05-24 11:48:32 UTC
  • mfrom: (13045.15.17 copies-use-overrides)
  • Revision ID: launchpad@pqm.canonical.com-20110524114832-oya6nkj2qd820p4w
[r=julian-edwards,
        wgrant][bug=783249] Add support for generic overrides to the package
        copier.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
    Or,
20
20
    SQL,
21
21
    )
 
22
from zope.component import getUtility
 
23
from zope.interface import (
 
24
    implements,
 
25
    Interface,
 
26
    )
22
27
 
23
28
from canonical.launchpad.components.decoratedresultset import (
24
29
    DecoratedResultSet,
26
31
from canonical.launchpad.interfaces.lpstorm import IStore
27
32
from lp.registry.model.sourcepackagename import SourcePackageName
28
33
from lp.services.database import bulk
 
34
from lp.soyuz.interfaces.component import IComponentSet
29
35
from lp.soyuz.interfaces.publishing import active_publishing_status
30
36
from lp.soyuz.model.binarypackagename import BinaryPackageName
31
37
from lp.soyuz.model.binarypackagerelease import BinaryPackageRelease
39
45
from lp.soyuz.model.sourcepackagerelease import SourcePackageRelease
40
46
 
41
47
 
 
48
class IOverridePolicy(Interface):
 
49
    """Override policy.
 
50
 
 
51
    An override policy returns overrides suitable for the given archive,
 
52
    distroseries, pocket for source or binary publications.
 
53
 
 
54
    For example, an implementation might allow existing publications to
 
55
    keep the same component and section as their ancestor publications.
 
56
    """
 
57
 
 
58
    def calculateSourceOverrides(archive, distroseries, pocket, sources):
 
59
        """Calculate source overrides.
 
60
 
 
61
        :param archive: The target `IArchive`.
 
62
        :param distroseries: The target `IDistroSeries`.
 
63
        :param pocket: The target `PackagePublishingPocket`.
 
64
        :param sources: A tuple of `ISourcePackageName`s.
 
65
 
 
66
        :return: A list of tuples containing `ISourcePackageName`,
 
67
            `IComponent` and `ISection`.
 
68
        """
 
69
        pass
 
70
 
 
71
    def calculateBinaryOverrides(archive, distroseries, pocket, binaries):
 
72
        """Calculate binary overrides.
 
73
 
 
74
        :param archive: The target `IArchive`.
 
75
        :param distroseries: The target `IDistroSeries`.
 
76
        :param pocket: The target `PackagePublishingPocket`.
 
77
        :param binaries: A tuple of `IBinaryPackageName`, architecturetag
 
78
            pairs. Architecturetag can be None for architecture-independent
 
79
            publications.
 
80
 
 
81
        :return: A list of tuples containing `IBinaryPackageName`,
 
82
            `IDistroArchSeries`, `IComponent`, `ISection` and
 
83
            `PackagePublishingPriority`.
 
84
        """
 
85
        pass
 
86
 
 
87
 
42
88
class BaseOverridePolicy:
43
89
 
 
90
    implements(IOverridePolicy)
 
91
 
44
92
    def calculateSourceOverrides(self, archive, distroseries, pocket,
45
93
                                 sources):
46
94
        raise NotImplementedError()
69
117
                (SourcePackageRelease.sourcepackagenameID,
70
118
                 SourcePackagePublishingHistory.componentID,
71
119
                 SourcePackagePublishingHistory.sectionID),
72
 
                SourcePackagePublishingHistory.pocket == pocket,
73
120
                SourcePackagePublishingHistory.archiveID == archive.id,
74
121
                SourcePackagePublishingHistory.distroseriesID ==
75
122
                    distroseries.id,
105
152
                 BinaryPackagePublishingHistory.componentID,
106
153
                 BinaryPackagePublishingHistory.sectionID,
107
154
                 BinaryPackagePublishingHistory.priority),
108
 
                BinaryPackagePublishingHistory.pocket == pocket,
109
155
                BinaryPackagePublishingHistory.status.is_in(
110
156
                    active_publishing_status),
111
157
                BinaryPackageRelease.id ==
136
182
    
137
183
    def calculateSourceOverrides(self, archive, distroseries, pocket,
138
184
                                 sources):
139
 
        default_component = archive.default_component or 'universe'
 
185
        default_component = archive.default_component or getUtility(
 
186
            IComponentSet)['universe']
140
187
        return [(source, default_component, None) for source in sources]
141
188
 
142
189
    def calculateBinaryOverrides(self, archive, distroseries, pocket,
143
190
                                 binaries):
144
 
        default_component = archive.default_component or 'universe'
 
191
        default_component = archive.default_component or getUtility(
 
192
            IComponentSet)['universe']
145
193
        return [
146
194
            (binary, das, default_component, None, None)
147
195
            for binary, das in calculate_target_das(distroseries, binaries)]