~launchpad-pqm/launchpad/devel

14538.2.49 by Curtis Hovey
Updated copyright.
1
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
8687.15.17 by Karl Fogel
Add the copyright header block to the rest of the files under lib/lp/.
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
4983.1.2 by Curtis Hovey
Added pylint exceptions to database classes.
4
# pylint: disable-msg=E0611,W0212
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
5
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
6
"""Classes to represent source package releases in a distribution series."""
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
7
8
__metaclass__ = type
9
10
__all__ = [
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
11
    'DistroSeriesSourcePackageRelease',
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
12
    ]
13
14550.1.1 by Steve Kowalik
Run format-imports over lib/lp and lib/canonical/launchpad
14
from operator import itemgetter
15
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
16
from lazr.delegates import delegates
13048.2.7 by Abel Deuring
Use storm to retrieve the data in DistroSeriesSourcePackageRelease.binaries; prejoin BinaryPackageName.
17
from storm.expr import (
18
    And,
19
    Desc,
20
    Join,
21
    )
13048.2.8 by Abel Deuring
Use the store self.distroseries for the query, instead of always using the main store.
22
from storm.store import Store
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
23
from zope.interface import implements
12412.1.1 by Robert Collins
Refactor lookups of target releases to do one getCurrentSourceReleases for all distros and one for all distroseries.
24
from zope.security.proxy import removeSecurityProxy
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
25
26
from canonical.database.sqlbase import sqlvalues
12742.3.45 by Gavin Panella
Belt and braces to ensure that DistroSeriesSourcePackageRelease are constructed correctly.
27
from lp.registry.interfaces.distroseries import IDistroSeries
14550.1.1 by Steve Kowalik
Run format-imports over lib/lp and lib/canonical/launchpad
28
from lp.services.database.decoratedresultset import DecoratedResultSet
12742.3.45 by Gavin Panella
Belt and braces to ensure that DistroSeriesSourcePackageRelease are constructed correctly.
29
from lp.soyuz.enums import PackagePublishingStatus
8447.1.2 by Jonathan Lange
Fix up lots of lint, including removing code that's been disabled forever.
30
from lp.soyuz.interfaces.distroseriessourcepackagerelease import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
31
    IDistroSeriesSourcePackageRelease,
32
    )
8294.6.1 by Julian Edwards
First stab at code-reorg. Still got a discrepancy on stuff I assigned to registry but not migrated yet.
33
from lp.soyuz.interfaces.sourcepackagerelease import ISourcePackageRelease
13048.2.7 by Abel Deuring
Use storm to retrieve the data in DistroSeriesSourcePackageRelease.binaries; prejoin BinaryPackageName.
34
from lp.soyuz.model.binarypackagebuild import BinaryPackageBuild
35
from lp.soyuz.model.binarypackagename import BinaryPackageName
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
36
from lp.soyuz.model.binarypackagerelease import BinaryPackageRelease
13048.2.7 by Abel Deuring
Use storm to retrieve the data in DistroSeriesSourcePackageRelease.binaries; prejoin BinaryPackageName.
37
from lp.soyuz.model.publishing import (
38
    BinaryPackagePublishingHistory,
39
    SourcePackagePublishingHistory,
40
    )
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
41
3851.3.2 by Francis J. Lacoste
Made DistributionSourcePackageRelease and DistroReleaseSourcePackageRelease implement correctly ISourcePackageRelease by using decorates.
42
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
43
class DistroSeriesSourcePackageRelease:
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
44
    """This is a "Magic SourcePackageRelease in Distro Release". It is not
45
    an SQLObject but instead it describes the behaviour of a specific
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
46
    release of the package in the distroseries."""
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
47
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
48
    implements(IDistroSeriesSourcePackageRelease)
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
49
7465.5.1 by Gary Poster
integrate lazr.config and lazr.delegates
50
    delegates(ISourcePackageRelease, context='sourcepackagerelease')
3851.3.2 by Francis J. Lacoste
Made DistributionSourcePackageRelease and DistroReleaseSourcePackageRelease implement correctly ISourcePackageRelease by using decorates.
51
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
52
    def __init__(self, distroseries, sourcepackagerelease):
12742.3.45 by Gavin Panella
Belt and braces to ensure that DistroSeriesSourcePackageRelease are constructed correctly.
53
        assert IDistroSeries.providedBy(distroseries)
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
54
        self.distroseries = distroseries
12742.3.45 by Gavin Panella
Belt and braces to ensure that DistroSeriesSourcePackageRelease are constructed correctly.
55
        assert ISourcePackageRelease.providedBy(sourcepackagerelease)
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
56
        self.sourcepackagerelease = sourcepackagerelease
57
58
    @property
59
    def distribution(self):
5796.7.3 by Muharem Hrnjadovic
changes stemming from danilo's review comments
60
        """See `IDistroSeriesSourcePackageRelease`."""
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
61
        return self.distroseries.distribution
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
62
63
    @property
6476.3.13 by Matthew Paul Thomas
Adds IDistroSeriesSourcePackageRelease.sourcepackage @property, so that links from distribution series pages to distribution series source package pages go to the right place.
64
    def sourcepackage(self):
65
        """See `IDistroSeriesSourcePackageRelease`."""
66
        return self.distroseries.getSourcePackage(self.sourcepackagename)
67
68
    @property
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
69
    def displayname(self):
5796.7.3 by Muharem Hrnjadovic
changes stemming from danilo's review comments
70
        """See `IDistroSeriesSourcePackageRelease`."""
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
71
        return '%s %s' % (self.name, self.version)
72
73
    @property
74
    def title(self):
5796.7.3 by Muharem Hrnjadovic
changes stemming from danilo's review comments
75
        """See `IDistroSeriesSourcePackageRelease`."""
9514.1.3 by Julian Edwards
Fix a load of page headings
76
        return '"%s" %s source package in %s' % (
77
            self.name, self.version, self.distroseries.title)
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
78
79
    @property
4920.2.3 by Mark Shuttleworth
Linkify ubuntu versions in distro source package overview page
80
    def version(self):
5796.7.3 by Muharem Hrnjadovic
changes stemming from danilo's review comments
81
        """See `IDistroSeriesSourcePackageRelease`."""
4920.2.3 by Mark Shuttleworth
Linkify ubuntu versions in distro source package overview page
82
        return self.sourcepackagerelease.version
83
84
    @property
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
85
    def pocket(self):
5796.7.3 by Muharem Hrnjadovic
changes stemming from danilo's review comments
86
        """See `IDistroSeriesSourcePackageRelease`."""
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
87
        currpub = self.current_publishing_record
88
        if currpub is None:
89
            return None
90
        return currpub.pocket
91
92
    @property
93
    def section(self):
5796.7.3 by Muharem Hrnjadovic
changes stemming from danilo's review comments
94
        """See `IDistroSeriesSourcePackageRelease`."""
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
95
        currpub = self.current_publishing_record
96
        if currpub is None:
97
            return None
98
        return currpub.section
99
100
    @property
101
    def component(self):
5796.7.3 by Muharem Hrnjadovic
changes stemming from danilo's review comments
102
        """See `IDistroSeriesSourcePackageRelease`."""
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
103
        currpub = self.current_publishing_record
104
        if currpub is None:
105
            return None
106
        return currpub.component
107
3500.4.27 by Celso Providelo
applying review comments, r=kiko.
108
# XXX cprov 20071026: heavy queries should be moved near to the related
109
# content classes in order to be better maintained.
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
110
    @property
111
    def builds(self):
5796.7.3 by Muharem Hrnjadovic
changes stemming from danilo's review comments
112
        """See `IDistroSeriesSourcePackageRelease`."""
8130.4.11 by Michael Nelson
Changes after chatting with cprov about the effects of the original change.
113
        # Find all the builds for the distribution and then filter them
114
        # for the current distroseries. We do this rather than separate
115
        # storm query because DSSPR will be removed later as part of the
116
        # planned package refactor.
117
118
        # Import DistributionSourcePackageRelease here to avoid circular
119
        # imports (and imported directly from database to avoid long line)
11869.8.3 by Jonathan Lange
Fix failing imports from most of the tests. Also clean up flakes.
120
        from lp.soyuz.model.distributionsourcepackagerelease import (
8130.4.11 by Michael Nelson
Changes after chatting with cprov about the effects of the original change.
121
            DistributionSourcePackageRelease)
122
123
        distro_builds = DistributionSourcePackageRelease(
124
            self.distroseries.distribution,
125
            self.sourcepackagerelease).builds
126
127
        return (
128
            [build for build in distro_builds
13048.2.7 by Abel Deuring
Use storm to retrieve the data in DistroSeriesSourcePackageRelease.binaries; prejoin BinaryPackageName.
129
             if build.distro_arch_series.distroseries == self.distroseries])
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
130
131
    @property
132
    def files(self):
5796.7.3 by Muharem Hrnjadovic
changes stemming from danilo's review comments
133
        """See `ISourcePackageRelease`."""
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
134
        return self.sourcepackagerelease.files
135
136
    @property
137
    def binaries(self):
5796.7.3 by Muharem Hrnjadovic
changes stemming from danilo's review comments
138
        """See `IDistroSeriesSourcePackageRelease`."""
13048.2.7 by Abel Deuring
Use storm to retrieve the data in DistroSeriesSourcePackageRelease.binaries; prejoin BinaryPackageName.
139
        # Avoid circular imports.
140
        from lp.soyuz.model.distroarchseries import DistroArchSeries
13048.2.8 by Abel Deuring
Use the store self.distroseries for the query, instead of always using the main store.
141
        store = Store.of(self.distroseries)
13048.2.7 by Abel Deuring
Use storm to retrieve the data in DistroSeriesSourcePackageRelease.binaries; prejoin BinaryPackageName.
142
        result_row = (
143
            BinaryPackageRelease, BinaryPackageBuild, BinaryPackageName)
144
145
        tables = (
146
            BinaryPackageRelease,
147
            Join(
148
                BinaryPackageBuild,
149
                BinaryPackageBuild.id == BinaryPackageRelease.buildID),
150
            Join(
151
                BinaryPackagePublishingHistory,
152
                BinaryPackageRelease.id ==
153
                BinaryPackagePublishingHistory.binarypackagereleaseID),
154
            Join(
155
                DistroArchSeries,
156
                DistroArchSeries.id ==
157
                BinaryPackagePublishingHistory.distroarchseriesID),
158
            Join(
159
                BinaryPackageName,
160
                BinaryPackageName.id ==
161
                BinaryPackageRelease.binarypackagenameID))
162
        archive_ids = list(
163
            self.distroseries.distribution.all_distro_archive_ids)
164
        binaries = store.using(*tables).find(
165
            result_row,
166
            And(
167
                DistroArchSeries.distroseriesID == self.distroseries.id,
168
                BinaryPackagePublishingHistory.archiveID.is_in(archive_ids),
169
                BinaryPackageBuild.source_package_release ==
170
                self.sourcepackagerelease))
171
        binaries.order_by(Desc(BinaryPackageRelease.id)).config(distinct=True)
172
        return DecoratedResultSet(binaries, itemgetter(0))
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
173
174
    @property
3686.1.45 by Celso Providelo
Fix bug #59318 (UI tweaks in SP & DRSPR pages) pagetest improvements
175
    def changesfile(self):
5796.7.3 by Muharem Hrnjadovic
changes stemming from danilo's review comments
176
        """See `IDistroSeriesSourcePackageRelease`."""
8537.6.1 by Celso Providelo
Re-implementing the PackageUpload lookups on SourcePackageRelese and Build in preparation to soyuz-delayed-copies.
177
        return self.sourcepackagerelease.upload_changesfile
3686.1.45 by Celso Providelo
Fix bug #59318 (UI tweaks in SP & DRSPR pages) pagetest improvements
178
179
    @property
4687.5.1 by Celso Providelo
Implementing package DELETION infrastructure.
180
    def published_binaries(self):
4687.5.17 by Celso Providelo
applying review comments, r=mwhudson.
181
        """See `IDistroSeriesSourcePackageRelease`."""
4687.5.1 by Celso Providelo
Implementing package DELETION infrastructure.
182
        target_binaries = []
183
184
        # Get the binary packages in each distroarchseries and store them
185
        # in target_binaries for returning.  We are looking for *published*
186
        # binarypackagereleases in all arches for the 'source' and its
187
        # location.
188
        for binary in self.binaries:
189
            if binary.architecturespecific:
7675.687.101 by Michael Nelson
package-meta-classes.txt
190
                considered_arches = [binary.build.distro_arch_series]
4687.5.1 by Celso Providelo
Implementing package DELETION infrastructure.
191
            else:
192
                considered_arches = self.distroseries.architectures
193
194
            for distroarchseries in considered_arches:
195
                dasbpr = distroarchseries.getBinaryPackage(
196
                    binary.name)[binary.version]
197
                # Only include objects with published binaries.
198
                if dasbpr is None or dasbpr.current_publishing_record is None:
199
                    continue
200
                target_binaries.append(dasbpr)
201
202
        return target_binaries
203
4687.7.2 by Celso Providelo
merging archive-removal-redesign-ppa change moving post-publication-operations API to publishing records.
204
#
205
# Publishing lookup methods.
206
#
207
208
    @property
209
    def publishing_history(self):
5796.7.3 by Muharem Hrnjadovic
changes stemming from danilo's review comments
210
        """See `IDistroSeriesSourcePackage`."""
12412.1.1 by Robert Collins
Refactor lookups of target releases to do one getCurrentSourceReleases for all distros and one for all distroseries.
211
        # sqlvalues bails on security proxied objects.
212
        archive_ids = removeSecurityProxy(
213
            self.distroseries.distribution.all_distro_archive_ids)
4687.7.2 by Celso Providelo
merging archive-removal-redesign-ppa change moving post-publication-operations API to publishing records.
214
        return SourcePackagePublishingHistory.select("""
5121.2.6 by Stuart Bishop
Some required code updates
215
            distroseries = %s AND
4687.7.2 by Celso Providelo
merging archive-removal-redesign-ppa change moving post-publication-operations API to publishing records.
216
            archive IN %s AND
217
            sourcepackagerelease = %s
218
            """ % sqlvalues(
219
                    self.distroseries,
12412.1.1 by Robert Collins
Refactor lookups of target releases to do one getCurrentSourceReleases for all distros and one for all distroseries.
220
                    archive_ids,
4687.7.2 by Celso Providelo
merging archive-removal-redesign-ppa change moving post-publication-operations API to publishing records.
221
                    self.sourcepackagerelease),
222
            orderBy='-datecreated')
223
224
    @property
225
    def current_publishing_record(self):
226
        """An internal property used by methods of this class to know where
227
        this release is or was published.
228
        """
229
        pub_hist = self.publishing_history
12180.1.7 by Julian Edwards
Fix unnecessary .count()s in model/distroseriessourcepackagerelease.py
230
        try:
231
            return pub_hist[0]
232
        except IndexError:
4687.7.2 by Celso Providelo
merging archive-removal-redesign-ppa change moving post-publication-operations API to publishing records.
233
            return None
234
235
    @property
236
    def current_published(self):
5796.7.3 by Muharem Hrnjadovic
changes stemming from danilo's review comments
237
        """See `IDistroArchSeriesSourcePackage`."""
4687.7.2 by Celso Providelo
merging archive-removal-redesign-ppa change moving post-publication-operations API to publishing records.
238
        # Retrieve current publishing info
5890.1.1 by Celso Providelo
Partially fixing bug #180218 (Override race-conditions). First we will consider PENDING publishing records as PUBLISHED for all override related operations.
239
        published_status = [
240
            PackagePublishingStatus.PENDING,
241
            PackagePublishingStatus.PUBLISHED]
4687.7.2 by Celso Providelo
merging archive-removal-redesign-ppa change moving post-publication-operations API to publishing records.
242
        current = SourcePackagePublishingHistory.selectFirst("""
5121.2.6 by Stuart Bishop
Some required code updates
243
        distroseries = %s AND
4687.7.2 by Celso Providelo
merging archive-removal-redesign-ppa change moving post-publication-operations API to publishing records.
244
        archive IN %s AND
245
        sourcepackagerelease = %s AND
5890.1.1 by Celso Providelo
Partially fixing bug #180218 (Override race-conditions). First we will consider PENDING publishing records as PUBLISHED for all override related operations.
246
        status IN %s
4687.7.2 by Celso Providelo
merging archive-removal-redesign-ppa change moving post-publication-operations API to publishing records.
247
        """ % sqlvalues(self.distroseries,
248
                        self.distroseries.distribution.all_distro_archive_ids,
249
                        self.sourcepackagerelease,
5890.1.1 by Celso Providelo
Partially fixing bug #180218 (Override race-conditions). First we will consider PENDING publishing records as PUBLISHED for all override related operations.
250
                        published_status),
251
            orderBy=['-datecreated', '-id'])
4687.7.2 by Celso Providelo
merging archive-removal-redesign-ppa change moving post-publication-operations API to publishing records.
252
253
        return current