~launchpad-pqm/launchpad/devel

13636.4.6 by Raphael Badin
Test instance against collections.Sequence instead of list.
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
1670 by Canonical.com Patch Queue Manager
Big lot of database clean-up r=stub except for resolution of conflicts.
5
6
__metaclass__ = type
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
7
__all__ = ['DistroArchSeries',
8
           'DistroArchSeriesSet',
2755 by Canonical.com Patch Queue Manager
[r=stevea] Fixing bug # 2812, loading zcml info in builddmaster and consequently removing the database imports, fixing bug # 1305 by using standards in both buildd cronscripts.
9
           'PocketChroot'
10
           ]
1670 by Canonical.com Patch Queue Manager
Big lot of database clean-up r=stub except for resolution of conflicts.
11
2457 by Canonical.com Patch Queue Manager
[r=lifeless] Launchpad Auto Build System User Interface Prototype (buildfarm UI) also minor fixes for buildd infrastructure, still needing mpt love.
12
from sqlobject import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
13
    BoolCol,
14
    ForeignKey,
15
    IntCol,
16
    SQLObjectNotFound,
17
    SQLRelatedJoin,
18
    StringCol,
19
    )
20
from storm.locals import (
21
    Join,
22
    SQL,
23
    )
8730.4.7 by Michael Nelson
Added arch-filtering for das.getBuildRecords() and dried-up tests.
24
from storm.store import EmptyResultSet
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
25
from zope.component import getUtility
26
from zope.interface import implements
2457 by Canonical.com Patch Queue Manager
[r=lifeless] Launchpad Auto Build System User Interface Prototype (buildfarm UI) also minor fixes for buildd infrastructure, still needing mpt love.
27
2736.1.8 by Mark Shuttleworth
test fixes, and pre-caching of binary and source package counts
28
from canonical.database.constants import DEFAULT
3691.373.5 by Christian Reis
Move DBSchema and Item into webapp.enum, and put EnumCol into canonical.database.enumcol
29
from canonical.database.enumcol import EnumCol
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
30
from canonical.database.sqlbase import (
31
    quote,
32
    quote_like,
33
    SQLBase,
34
    sqlvalues,
35
    )
14593.2.15 by Curtis Hovey
Moved helpers to lp.services.
36
from lp.services.helpers import shortlist
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
37
from canonical.launchpad.webapp.interfaces import (
38
    IStoreSelector,
39
    MAIN_STORE,
40
    SLAVE_FLAVOR,
41
    )
42
from lp.registry.interfaces.person import validate_public_person
9113.7.7 by Jonathan Lange
Update all the rest of the imports of PackagePublishingPocket.
43
from lp.registry.interfaces.pocket import PackagePublishingPocket
14550.1.1 by Steve Kowalik
Run format-imports over lib/lp and lib/canonical/launchpad
44
from lp.services.database.decoratedresultset import DecoratedResultSet
11411.6.12 by Julian Edwards
Move PackagePublishingStatus/Priority
45
from lp.soyuz.enums import PackagePublishingStatus
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
46
from lp.soyuz.interfaces.binarypackagebuild import IBinaryPackageBuildSet
8294.6.3 by Julian Edwards
Distroarchseries is now part of lp.soyuz
47
from lp.soyuz.interfaces.binarypackagename import IBinaryPackageName
10085.1.11 by Jonathan Lange
Fix the rest.
48
from lp.soyuz.interfaces.buildrecords import IHasBuildRecords
8294.6.3 by Julian Edwards
Distroarchseries is now part of lp.soyuz
49
from lp.soyuz.interfaces.distroarchseries import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
50
    IDistroArchSeries,
51
    IDistroArchSeriesSet,
52
    IPocketChroot,
53
    )
13636.4.2 by Raphael Badin
Also limit the checks to the optional source names selected for the initialization.
54
from lp.soyuz.interfaces.publishing import ICanPublishPackages
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.
55
from lp.soyuz.model.binarypackagename import BinaryPackageName
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
56
from lp.soyuz.model.binarypackagerelease import BinaryPackageRelease
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.
57
from lp.soyuz.model.distroarchseriesbinarypackage import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
58
    DistroArchSeriesBinaryPackage,
59
    )
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.
60
from lp.soyuz.model.processor import Processor
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
61
from lp.soyuz.model.publishing import BinaryPackagePublishingHistory
62
1670 by Canonical.com Patch Queue Manager
Big lot of database clean-up r=stub except for resolution of conflicts.
63
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
64
class DistroArchSeries(SQLBase):
5019.1.15 by Christian Robottom Reis
Simplify publication interfaces.
65
    implements(IDistroArchSeries, IHasBuildRecords, ICanPublishPackages)
5121.2.6 by Stuart Bishop
Some required code updates
66
    _table = 'DistroArchSeries'
3691.93.25 by Christian Reis
Fix architecture handling in the queue builder. Make architecturehintlist NOT NULL and fix sampledata for it. Clean up the portions of the buildmaster script related to build creation. Severely enhance and clarify the buildd-queuebuilder test. As an added bonus clean up the filechunks() methods and instead use librarian.utils.
67
    _defaultOrder = 'id'
1442 by Canonical.com Patch Queue Manager
brand new look for distroarchrelease, and fixed dar file layout
68
5121.2.6 by Stuart Bishop
Some required code updates
69
    distroseries = ForeignKey(dbName='distroseries',
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
70
        foreignKey='DistroSeries', notNull=True)
1442 by Canonical.com Patch Queue Manager
brand new look for distroarchrelease, and fixed dar file layout
71
    processorfamily = ForeignKey(dbName='processorfamily',
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
72
        foreignKey='ProcessorFamily', notNull=True)
73
    architecturetag = StringCol(notNull=True)
74
    official = BoolCol(notNull=True)
5485.1.17 by Edwin Grubbs
Fixed indentation
75
    owner = ForeignKey(
76
        dbName='owner', foreignKey='Person',
5821.2.40 by James Henstridge
* Move all the uses of public_person_validator over to the Storm
77
        storm_validator=validate_public_person, notNull=True)
2736.1.8 by Mark Shuttleworth
test fixes, and pre-caching of binary and source package counts
78
    package_count = IntCol(notNull=True, default=DEFAULT)
6138.2.2 by Muharem Hrnjadovic
name changes
79
    supports_virtualized = BoolCol(notNull=False, default=False)
7675.817.2 by Julian Edwards
Add model definition and test
80
    enabled = BoolCol(notNull=False, default=True)
1442 by Canonical.com Patch Queue Manager
brand new look for distroarchrelease, and fixed dar file layout
81
3504.1.13 by kiko
Implement initial SQLRelatedJoin migration across Launchpad tree. Still needs to reconsider the Snapshot approach which will be a big performance hit.
82
    packages = SQLRelatedJoin('BinaryPackageRelease',
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
83
        joinColumn='distroarchseries',
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
84
        intermediateTable='BinaryPackagePublishing',
85
        otherColumn='binarypackagerelease')
86
87
    def __getitem__(self, name):
88
        return self.getBinaryPackage(name)
1442 by Canonical.com Patch Queue Manager
brand new look for distroarchrelease, and fixed dar file layout
89
2591 by Canonical.com Patch Queue Manager
[trivial] fixing builddUI bits, limit distrorelease/distroarchrelease +builds pages results until define some batching style.
90
    @property
2755 by Canonical.com Patch Queue Manager
[r=stevea] Fixing bug # 2812, loading zcml info in builddmaster and consequently removing the database imports, fixing bug # 1305 by using standards in both buildd cronscripts.
91
    def default_processor(self):
6476.3.18 by Matthew Paul Thomas
Applies fixes from Julian Edwards' review.
92
        """See `IDistroArchSeries`."""
4664.1.1 by Curtis Hovey
Normalized comments for bug 3732.
93
        # XXX cprov 2005-08-31:
6476.3.5 by Matthew Paul Thomas
Fixes distribution series architecture binary package pages.
94
        # This could possibly be better designed; let's think about it in
3691.93.25 by Christian Reis
Fix architecture handling in the queue builder. Make architecturehintlist NOT NULL and fix sampledata for it. Clean up the portions of the buildmaster script related to build creation. Severely enhance and clarify the buildd-queuebuilder test. As an added bonus clean up the filechunks() methods and instead use librarian.utils.
95
        # the future. Pick the first processor we found for this
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
96
        # distroarchseries.processorfamily. The data model should
3691.93.25 by Christian Reis
Fix architecture handling in the queue builder. Make architecturehintlist NOT NULL and fix sampledata for it. Clean up the portions of the buildmaster script related to build creation. Severely enhance and clarify the buildd-queuebuilder test. As an added bonus clean up the filechunks() methods and instead use librarian.utils.
97
        # change to have a default processor for a processorfamily
2755 by Canonical.com Patch Queue Manager
[r=stevea] Fixing bug # 2812, loading zcml info in builddmaster and consequently removing the database imports, fixing bug # 1305 by using standards in both buildd cronscripts.
98
        return self.processors[0]
2772.1.23 by Celso Providelo
applying review comments (except widget issue) and removing trailling whitspaces (emacs-fu) from some files, tests passing
99
2755 by Canonical.com Patch Queue Manager
[r=stevea] Fixing bug # 2812, loading zcml info in builddmaster and consequently removing the database imports, fixing bug # 1305 by using standards in both buildd cronscripts.
100
    @property
101
    def processors(self):
6476.3.18 by Matthew Paul Thomas
Applies fixes from Julian Edwards' review.
102
        """See `IDistroArchSeries`."""
3691.62.21 by kiko
Clean up the use of ID/.id in select*By and constructors
103
        return Processor.selectBy(family=self.processorfamily, orderBy='id')
2755 by Canonical.com Patch Queue Manager
[r=stevea] Fixing bug # 2812, loading zcml info in builddmaster and consequently removing the database imports, fixing bug # 1305 by using standards in both buildd cronscripts.
104
105
    @property
1670 by Canonical.com Patch Queue Manager
Big lot of database clean-up r=stub except for resolution of conflicts.
106
    def title(self):
6476.3.18 by Matthew Paul Thomas
Applies fixes from Julian Edwards' review.
107
        """See `IDistroArchSeries`."""
2591 by Canonical.com Patch Queue Manager
[trivial] fixing builddUI bits, limit distrorelease/distroarchrelease +builds pages results until define some batching style.
108
        return '%s for %s (%s)' % (
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
109
            self.distroseries.title, self.architecturetag,
2591 by Canonical.com Patch Queue Manager
[trivial] fixing builddUI bits, limit distrorelease/distroarchrelease +builds pages results until define some batching style.
110
            self.processorfamily.name
111
            )
1716.1.218 by Christian Reis
Add more package data and update the gina doctest. Seriously whack packages.py and gina.py, with some trickle into handlers.py. The creation of source packages for Hoary is now minimally tested, with most important codepaths and error conditions being checked. Did work on validation and ensuring the source and binary package data we have is consistent. Added a ton of packages to the gina test archive so we can use them in our tests -- welcome them into rocketfuel :-)
112
2591 by Canonical.com Patch Queue Manager
[trivial] fixing builddUI bits, limit distrorelease/distroarchrelease +builds pages results until define some batching style.
113
    @property
2736.1.6 by Mark Shuttleworth
polish distro pacakge views and searching
114
    def displayname(self):
6476.3.18 by Matthew Paul Thomas
Applies fixes from Julian Edwards' review.
115
        """See `IDistroArchSeries`."""
6476.3.5 by Matthew Paul Thomas
Fixes distribution series architecture binary package pages.
116
        return '%s %s %s' % (
117
            self.distroseries.distribution.displayname,
118
            self.distroseries.displayname, self.architecturetag)
2772.1.23 by Celso Providelo
applying review comments (except widget issue) and removing trailling whitspaces (emacs-fu) from some files, tests passing
119
2736.1.8 by Mark Shuttleworth
test fixes, and pre-caching of binary and source package counts
120
    def updatePackageCount(self):
6476.3.18 by Matthew Paul Thomas
Applies fixes from Julian Edwards' review.
121
        """See `IDistroArchSeries`."""
2736.1.8 by Mark Shuttleworth
test fixes, and pre-caching of binary and source package counts
122
        query = """
5121.2.6 by Stuart Bishop
Some required code updates
123
            BinaryPackagePublishingHistory.distroarchseries = %s AND
4376.2.6 by Julian Edwards
Fix mistakes from previous commit.
124
            BinaryPackagePublishingHistory.archive IN %s AND
3496.1.87 by Celso Providelo
remove all callsites and permission for Source/BinaryPackagePublishing
125
            BinaryPackagePublishingHistory.status = %s AND
126
            BinaryPackagePublishingHistory.pocket = %s
2736.1.8 by Mark Shuttleworth
test fixes, and pre-caching of binary and source package counts
127
            """ % sqlvalues(
3496.1.87 by Celso Providelo
remove all callsites and permission for Source/BinaryPackagePublishing
128
                    self,
4376.2.73 by Julian Edwards
Apply review comments.
129
                    self.distroseries.distribution.all_distro_archive_ids,
3500.2.40 by Celso Providelo
Extend the encapsulated API for publishing to DistroRelease/DistroArchRelease via IPublishing.
130
                    PackagePublishingStatus.PUBLISHED,
131
                    PackagePublishingPocket.RELEASE
2736.1.8 by Mark Shuttleworth
test fixes, and pre-caching of binary and source package counts
132
                 )
3496.1.87 by Celso Providelo
remove all callsites and permission for Source/BinaryPackagePublishing
133
        self.package_count = BinaryPackagePublishingHistory.select(
134
            query).count()
1442 by Canonical.com Patch Queue Manager
brand new look for distroarchrelease, and fixed dar file layout
135
2663 by Canonical.com Patch Queue Manager
[r=stevea] Landing NominatedArchIndep changes.
136
    @property
137
    def isNominatedArchIndep(self):
6476.3.18 by Matthew Paul Thomas
Applies fixes from Julian Edwards' review.
138
        """See `IDistroArchSeries`."""
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
139
        return (self.distroseries.nominatedarchindep and
140
                self.id == self.distroseries.nominatedarchindep.id)
1716.1.218 by Christian Reis
Add more package data and update the gina doctest. Seriously whack packages.py and gina.py, with some trickle into handlers.py. The creation of source packages for Hoary is now minimally tested, with most important codepaths and error conditions being checked. Did work on validation and ensuring the source and binary package data we have is consistent. Added a ton of packages to the gina test archive so we can use them in our tests -- welcome them into rocketfuel :-)
141
5008.3.4 by Julian Edwards
Pocket is no longer a valid argument when dealing with chroots; there is
142
    def getPocketChroot(self):
6476.3.18 by Matthew Paul Thomas
Applies fixes from Julian Edwards' review.
143
        """See `IDistroArchSeries`."""
5008.3.4 by Julian Edwards
Pocket is no longer a valid argument when dealing with chroots; there is
144
        pchroot = PocketChroot.selectOneBy(distroarchseries=self)
3496.1.67 by Celso Providelo
review comments step 2, changing API, better debug for ChrootManager and allowing md5 attribute to ILFC
145
        return pchroot
146
5008.3.4 by Julian Edwards
Pocket is no longer a valid argument when dealing with chroots; there is
147
    def getChroot(self, default=None):
6476.3.18 by Matthew Paul Thomas
Applies fixes from Julian Edwards' review.
148
        """See `IDistroArchSeries`."""
5008.3.4 by Julian Edwards
Pocket is no longer a valid argument when dealing with chroots; there is
149
        pocket_chroot = self.getPocketChroot()
3496.1.67 by Celso Providelo
review comments step 2, changing API, better debug for ChrootManager and allowing md5 attribute to ILFC
150
151
        if pocket_chroot is None:
3496.1.62 by Celso Providelo
Fixing and redesigning of manage-chroot tool and IPocketChroot
152
            return default
153
3496.1.67 by Celso Providelo
review comments step 2, changing API, better debug for ChrootManager and allowing md5 attribute to ILFC
154
        return pocket_chroot.chroot
3496.1.62 by Celso Providelo
Fixing and redesigning of manage-chroot tool and IPocketChroot
155
10351.1.1 by William Grant
Add, export and test DAS.chroot_url. Also move the DAS webservice doctest.
156
    @property
157
    def chroot_url(self):
10351.1.3 by William Grant
Add missing docstring.
158
        """See `IDistroArchSeries`."""
10351.1.1 by William Grant
Add, export and test DAS.chroot_url. Also move the DAS webservice doctest.
159
        chroot = self.getChroot()
160
        if chroot is None:
161
            return None
162
        return chroot.http_url
163
5008.3.4 by Julian Edwards
Pocket is no longer a valid argument when dealing with chroots; there is
164
    def addOrUpdateChroot(self, chroot):
6476.3.18 by Matthew Paul Thomas
Applies fixes from Julian Edwards' review.
165
        """See `IDistroArchSeries`."""
5008.3.4 by Julian Edwards
Pocket is no longer a valid argument when dealing with chroots; there is
166
        pocket_chroot = self.getPocketChroot()
3496.1.62 by Celso Providelo
Fixing and redesigning of manage-chroot tool and IPocketChroot
167
168
        if pocket_chroot is None:
5008.3.4 by Julian Edwards
Pocket is no longer a valid argument when dealing with chroots; there is
169
            return PocketChroot(distroarchseries=self, chroot=chroot)
3496.1.62 by Celso Providelo
Fixing and redesigning of manage-chroot tool and IPocketChroot
170
        else:
171
            pocket_chroot.chroot = chroot
172
173
        return pocket_chroot
1716.1.218 by Christian Reis
Add more package data and update the gina doctest. Seriously whack packages.py and gina.py, with some trickle into handlers.py. The creation of source packages for Hoary is now minimally tested, with most important codepaths and error conditions being checked. Did work on validation and ensuring the source and binary package data we have is consistent. Added a ton of packages to the gina test archive so we can use them in our tests -- welcome them into rocketfuel :-)
174
2736.1.6 by Mark Shuttleworth
polish distro pacakge views and searching
175
    def searchBinaryPackages(self, text):
6476.3.18 by Matthew Paul Thomas
Applies fixes from Julian Edwards' review.
176
        """See `IDistroArchSeries`."""
7434.2.1 by Michael Nelson
Modified package searches on IDistribution, IDistroSeries and
177
        store = getUtility(IStoreSelector).get(MAIN_STORE, SLAVE_FLAVOR)
7310.4.3 by Michael Nelson
Updated searches on Distribution, DistroSeries and DistroArchSeries
178
        origin = [
179
            BinaryPackageRelease,
180
            Join(
181
                BinaryPackagePublishingHistory,
182
                BinaryPackagePublishingHistory.binarypackagerelease ==
183
                    BinaryPackageRelease.id
184
                ),
185
            Join(
186
                BinaryPackageName,
187
                BinaryPackageRelease.binarypackagename ==
188
                    BinaryPackageName.id
189
                )
190
            ]
12245.3.2 by Julian Edwards
speed up the search query when there's no text supplied by removing the FTI stuff.
191
        if text:
192
            find_spec = (
193
                BinaryPackageRelease,
194
                BinaryPackageName,
195
                SQL("rank(BinaryPackageRelease.fti, ftq(%s)) AS rank" %
196
                    sqlvalues(text))
197
                )
198
        else:
199
            find_spec = (
200
                BinaryPackageRelease,
201
                BinaryPackageName,
13636.4.2 by Raphael Badin
Also limit the checks to the optional source names selected for the initialization.
202
                BinaryPackageName,  # dummy value
12245.3.2 by Julian Edwards
speed up the search query when there's no text supplied by removing the FTI stuff.
203
                )
4868.3.9 by Celso Providelo
applying review comments, r=kiko.
204
        archives = self.distroseries.distribution.getArchiveIDList()
7310.4.8 by Michael Nelson
Recommended changes from Graham's review. Mostly cosmetic, but
205
206
        # Note: When attempting to convert the query below into straight
207
        # Storm expressions, a 'tuple index out-of-range' error was always
208
        # raised.
12245.3.2 by Julian Edwards
speed up the search query when there's no text supplied by removing the FTI stuff.
209
        query = """
210
            BinaryPackagePublishingHistory.distroarchseries = %s AND
211
            BinaryPackagePublishingHistory.archive IN %s AND
212
            BinaryPackagePublishingHistory.dateremoved is NULL
213
            """ % (quote(self), quote(archives))
214
        if text:
215
            query += """
216
            AND (BinaryPackageRelease.fti @@ ftq(%s) OR
217
            BinaryPackageName.name ILIKE '%%' || %s || '%%')
218
            """ % (quote(text), quote_like(text))
7310.4.3 by Michael Nelson
Updated searches on Distribution, DistroSeries and DistroArchSeries
219
        result = store.using(*origin).find(
12245.3.2 by Julian Edwards
speed up the search query when there's no text supplied by removing the FTI stuff.
220
            find_spec, query).config(distinct=True)
7310.4.3 by Michael Nelson
Updated searches on Distribution, DistroSeries and DistroArchSeries
221
12245.3.2 by Julian Edwards
speed up the search query when there's no text supplied by removing the FTI stuff.
222
        if text:
223
            result = result.order_by("rank DESC, BinaryPackageName.name")
224
        else:
225
            result = result.order_by("BinaryPackageName.name")
7310.4.3 by Michael Nelson
Updated searches on Distribution, DistroSeries and DistroArchSeries
226
2736.1.6 by Mark Shuttleworth
polish distro pacakge views and searching
227
        # import here to avoid circular import problems
11869.8.3 by Jonathan Lange
Fix failing imports from most of the tests. Also clean up flakes.
228
        from lp.soyuz.model.distroarchseriesbinarypackagerelease import (
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
229
            DistroArchSeriesBinaryPackageRelease)
7310.4.3 by Michael Nelson
Updated searches on Distribution, DistroSeries and DistroArchSeries
230
231
        # Create a function that will decorate the results, converting
232
        # them from the find_spec above into DASBPRs:
233
        def result_to_dasbpr(
7310.4.8 by Michael Nelson
Recommended changes from Graham's review. Mostly cosmetic, but
234
            (binary_package_release, binary_package_name, rank)):
7310.4.3 by Michael Nelson
Updated searches on Distribution, DistroSeries and DistroArchSeries
235
            return DistroArchSeriesBinaryPackageRelease(
236
                distroarchseries=self,
7310.4.8 by Michael Nelson
Recommended changes from Graham's review. Mostly cosmetic, but
237
                binarypackagerelease=binary_package_release)
7310.4.3 by Michael Nelson
Updated searches on Distribution, DistroSeries and DistroArchSeries
238
239
        # Return the decorated result set so the consumer of these
240
        # results will only see DSPs
241
        return DecoratedResultSet(result, result_to_dasbpr)
2736.1.6 by Mark Shuttleworth
polish distro pacakge views and searching
242
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
243
    def getBinaryPackage(self, name):
6476.3.18 by Matthew Paul Thomas
Applies fixes from Julian Edwards' review.
244
        """See `IDistroArchSeries`."""
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
245
        if not IBinaryPackageName.providedBy(name):
246
            try:
247
                name = BinaryPackageName.byName(name)
248
            except SQLObjectNotFound:
249
                return None
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
250
        return DistroArchSeriesBinaryPackage(
2705 by Canonical.com Patch Queue Manager
r=spiv, mark's soyuz loving.
251
            self, name)
1442 by Canonical.com Patch Queue Manager
brand new look for distroarchrelease, and fixed dar file layout
252
5565.5.11 by Julian Edwards
Hide private builds data (in private PPAs) from the UI.
253
    def getBuildRecords(self, build_state=None, name=None, pocket=None,
11005.3.30 by Michael Nelson
Added binary_only to the signature for distro and distroarchseries.
254
                        arch_tag=None, user=None, binary_only=True):
2666 by Canonical.com Patch Queue Manager
[r=stevea] Missing +builds page for distribution, reusing code from build-list.pt
255
        """See IHasBuildRecords"""
5565.5.11 by Julian Edwards
Hide private builds data (in private PPAs) from the UI.
256
        # Ignore "user", since it would not make any difference to the
257
        # records returned here (private builds are only in PPA right
258
        # now).
11005.3.30 by Michael Nelson
Added binary_only to the signature for distro and distroarchseries.
259
        # Ignore "binary_only" as for a distro arch series it is only
260
        # the binaries that are relevant.
5565.5.11 by Julian Edwards
Hide private builds data (in private PPAs) from the UI.
261
8730.4.7 by Michael Nelson
Added arch-filtering for das.getBuildRecords() and dried-up tests.
262
        # For consistency we return an empty resultset if arch_tag
263
        # is provided but doesn't match our architecture.
264
        if arch_tag is not None and arch_tag != self.architecturetag:
265
            return EmptyResultSet()
266
10667.2.2 by Michael Nelson
Mass renaming of imports and references to IBuild/Build/IBuildSet
267
        # Use the facility provided by IBinaryPackageBuildSet to
268
        # retrieve the records.
269
        return getUtility(IBinaryPackageBuildSet).getBuildsByArchIds(
11316.2.1 by William Grant
getBuildsByArchIds now takes a distribution, and uses its precalculated all_distro_archive_ids rather than joining against Archive. The Archive join makes the query an order of magnitude slower.
270
            self.distroseries.distribution, [self.id], build_state, name,
271
            pocket)
2666 by Canonical.com Patch Queue Manager
[r=stevea] Missing +builds page for distribution, reusing code from build-list.pt
272
3147.2.53 by Celso Providelo
Implement backports-version sanity checks
273
    def getReleasedPackages(self, binary_name, pocket=None,
3691.443.52 by Celso Providelo
Fix #88612 (PPA uploads should be submitted to auto-overrides procedure).
274
                            include_pending=False, exclude_pocket=None,
275
                            archive=None):
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
276
        """See IDistroArchSeries."""
3147.2.52 by Celso Providelo
Redesign Overriding code in nascent upload, do no check against BACKPORTS version if the upload isn't target to this pocket.
277
        queries = []
278
3147.2.53 by Celso Providelo
Implement backports-version sanity checks
279
        if not IBinaryPackageName.providedBy(binary_name):
3691.143.6 by Malcolm Cleaton
Fix for dar.getReleasedPackages trying to create binarypackagename entries.
280
            binary_name = BinaryPackageName.byName(binary_name)
3147.2.52 by Celso Providelo
Redesign Overriding code in nascent upload, do no check against BACKPORTS version if the upload isn't target to this pocket.
281
282
        queries.append("""
283
        binarypackagerelease=binarypackagerelease.id AND
284
        binarypackagerelease.binarypackagename=%s AND
5121.2.6 by Stuart Bishop
Some required code updates
285
        distroarchseries = %s
3691.443.52 by Celso Providelo
Fix #88612 (PPA uploads should be submitted to auto-overrides procedure).
286
        """ % sqlvalues(binary_name, self))
3147.2.52 by Celso Providelo
Redesign Overriding code in nascent upload, do no check against BACKPORTS version if the upload isn't target to this pocket.
287
2694 by Canonical.com Patch Queue Manager
Bits and bobs on distro{arch,}release. r=stevea
288
        if pocket is not None:
3147.2.52 by Celso Providelo
Redesign Overriding code in nascent upload, do no check against BACKPORTS version if the upload isn't target to this pocket.
289
            queries.append("pocket=%s" % sqlvalues(pocket.value))
290
291
        if exclude_pocket is not None:
292
            queries.append("pocket!=%s" % sqlvalues(exclude_pocket.value))
293
294
        if include_pending:
295
            queries.append("status in (%s, %s)" % sqlvalues(
3500.2.40 by Celso Providelo
Extend the encapsulated API for publishing to DistroRelease/DistroArchRelease via IPublishing.
296
                PackagePublishingStatus.PUBLISHED,
297
                PackagePublishingStatus.PENDING))
3147.2.52 by Celso Providelo
Redesign Overriding code in nascent upload, do no check against BACKPORTS version if the upload isn't target to this pocket.
298
        else:
299
            queries.append("status=%s" % sqlvalues(
3500.2.40 by Celso Providelo
Extend the encapsulated API for publishing to DistroRelease/DistroArchRelease via IPublishing.
300
                PackagePublishingStatus.PUBLISHED))
3147.2.52 by Celso Providelo
Redesign Overriding code in nascent upload, do no check against BACKPORTS version if the upload isn't target to this pocket.
301
4868.3.9 by Celso Providelo
applying review comments, r=kiko.
302
        archives = self.distroseries.distribution.getArchiveIDList(archive)
4376.2.6 by Julian Edwards
Fix mistakes from previous commit.
303
        queries.append("archive IN %s" % sqlvalues(archives))
3691.443.52 by Celso Providelo
Fix #88612 (PPA uploads should be submitted to auto-overrides procedure).
304
3496.1.87 by Celso Providelo
remove all callsites and permission for Source/BinaryPackagePublishing
305
        published = BinaryPackagePublishingHistory.select(
3147.2.52 by Celso Providelo
Redesign Overriding code in nascent upload, do no check against BACKPORTS version if the upload isn't target to this pocket.
306
            " AND ".join(queries),
13636.4.2 by Raphael Badin
Also limit the checks to the optional source names selected for the initialization.
307
            clauseTables=['BinaryPackageRelease'],
4868.3.2 by Celso Providelo
Allowing PPA version checks and auto-overrides.
308
            orderBy=['-id'])
3147.2.52 by Celso Providelo
Redesign Overriding code in nascent upload, do no check against BACKPORTS version if the upload isn't target to this pocket.
309
2694 by Canonical.com Patch Queue Manager
Bits and bobs on distro{arch,}release. r=stevea
310
        return shortlist(published)
2772.1.23 by Celso Providelo
applying review comments (except widget issue) and removing trailling whitspaces (emacs-fu) from some files, tests passing
311
3691.443.22 by Celso Providelo
merge from jamesh (collapse PPA into Archive) and fixing tests. It is working.
312
    def getPendingPublications(self, archive, pocket, is_careful):
6476.3.18 by Matthew Paul Thomas
Applies fixes from Julian Edwards' review.
313
        """See `ICanPublishPackages`."""
3691.443.22 by Celso Providelo
merge from jamesh (collapse PPA into Archive) and fixing tests. It is working.
314
        queries = [
5121.2.6 by Stuart Bishop
Some required code updates
315
            "distroarchseries = %s AND archive = %s"
3691.443.22 by Celso Providelo
merge from jamesh (collapse PPA into Archive) and fixing tests. It is working.
316
            % sqlvalues(self, archive)
317
            ]
3686.1.70 by Celso Providelo
Fix bug #78082 and land more realiable test for it, code is still not refactored in proper way, there is a nasty duplication in IDistro{Arch}Release.publish API.
318
319
        target_status = [PackagePublishingStatus.PENDING]
320
        if is_careful:
321
            target_status.append(PackagePublishingStatus.PUBLISHED)
322
        queries.append("status IN %s" % sqlvalues(target_status))
323
324
        # restrict to a specific pocket.
325
        queries.append('pocket = %s' % sqlvalues(pocket))
3691.448.1 by Celso Providelo
making Publishing system archive-centric, publishing phase unit-tested
326
4767.4.1 by Julian Edwards
Allow commercial to publish anything, anytime, anywhere.
327
        # Exclude RELEASE pocket if the distroseries was already released,
4767.4.4 by Julian Edwards
Apply kiko review comments.
328
        # since it should not change, unless the archive allows it.
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
329
        if (not self.distroseries.isUnstable() and
4767.4.4 by Julian Edwards
Apply kiko review comments.
330
            not archive.allowUpdatesToReleasePocket()):
3691.448.1 by Celso Providelo
making Publishing system archive-centric, publishing phase unit-tested
331
            queries.append(
3686.1.70 by Celso Providelo
Fix bug #78082 and land more realiable test for it, code is still not refactored in proper way, there is a nasty duplication in IDistro{Arch}Release.publish API.
332
            'pocket != %s' % sqlvalues(PackagePublishingPocket.RELEASE))
3691.448.1 by Celso Providelo
making Publishing system archive-centric, publishing phase unit-tested
333
3686.1.70 by Celso Providelo
Fix bug #78082 and land more realiable test for it, code is still not refactored in proper way, there is a nasty duplication in IDistro{Arch}Release.publish API.
334
        publications = BinaryPackagePublishingHistory.select(
335
                    " AND ".join(queries), orderBy=["-id"])
3691.448.1 by Celso Providelo
making Publishing system archive-centric, publishing phase unit-tested
336
3686.1.70 by Celso Providelo
Fix bug #78082 and land more realiable test for it, code is still not refactored in proper way, there is a nasty duplication in IDistro{Arch}Release.publish API.
337
        return publications
338
3691.448.14 by Celso Providelo
merge from archive-rework
339
    def publish(self, diskpool, log, archive, pocket, is_careful=False):
6476.3.18 by Matthew Paul Thomas
Applies fixes from Julian Edwards' review.
340
        """See `ICanPublishPackages`."""
3500.4.1 by Celso Providelo
review comments frm bjorn, fixing tests
341
        log.debug("Attempting to publish pending binaries for %s"
342
              % self.architecturetag)
343
3691.93.8 by Christian Reis
Step 3: change dirty_pockets to be a set, and update API accordingly. Implement checkLegalPocket in DistroRelease, and use it to sanity-check and log publish() calls.
344
        dirty_pockets = set()
3686.1.70 by Celso Providelo
Fix bug #78082 and land more realiable test for it, code is still not refactored in proper way, there is a nasty duplication in IDistro{Arch}Release.publish API.
345
3691.443.22 by Celso Providelo
merge from jamesh (collapse PPA into Archive) and fixing tests. It is working.
346
        for bpph in self.getPendingPublications(archive, pocket, is_careful):
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
347
            if not self.distroseries.checkLegalPocket(
3691.443.86 by Celso Providelo
merge from RF
348
                bpph, is_careful, log):
3691.93.8 by Christian Reis
Step 3: change dirty_pockets to be a set, and update API accordingly. Implement checkLegalPocket in DistroRelease, and use it to sanity-check and log publish() calls.
349
                continue
3496.1.87 by Celso Providelo
remove all callsites and permission for Source/BinaryPackagePublishing
350
            bpph.publish(diskpool, log)
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
351
            dirty_pockets.add((self.distroseries.name, bpph.pocket))
3496.1.89 by Celso Providelo
merge from RF, fix 5 conflicts
352
3691.93.8 by Christian Reis
Step 3: change dirty_pockets to be a set, and update API accordingly. Implement checkLegalPocket in DistroRelease, and use it to sanity-check and log publish() calls.
353
        return dirty_pockets
3500.2.40 by Celso Providelo
Extend the encapsulated API for publishing to DistroRelease/DistroArchRelease via IPublishing.
354
3691.441.17 by Malcolm Cleaton
General fixing
355
    @property
356
    def main_archive(self):
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
357
        return self.distroseries.distribution.main_archive
358
359
360
class DistroArchSeriesSet:
361
    """This class is to deal with DistroArchSeries related stuff"""
362
363
    implements(IDistroArchSeriesSet)
2755 by Canonical.com Patch Queue Manager
[r=stevea] Fixing bug # 2812, loading zcml info in builddmaster and consequently removing the database imports, fixing bug # 1305 by using standards in both buildd cronscripts.
364
365
    def __iter__(self):
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
366
        return iter(DistroArchSeries.select())
2772.1.23 by Celso Providelo
applying review comments (except widget issue) and removing trailling whitspaces (emacs-fu) from some files, tests passing
367
2755 by Canonical.com Patch Queue Manager
[r=stevea] Fixing bug # 2812, loading zcml info in builddmaster and consequently removing the database imports, fixing bug # 1305 by using standards in both buildd cronscripts.
368
    def get(self, dar_id):
14583.1.21 by Curtis Hovey
Fixed doc.
369
        """See `IDistributionSet`."""
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
370
        return DistroArchSeries.get(dar_id)
2755 by Canonical.com Patch Queue Manager
[r=stevea] Fixing bug # 2812, loading zcml info in builddmaster and consequently removing the database imports, fixing bug # 1305 by using standards in both buildd cronscripts.
371
372
    def count(self):
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
373
        return DistroArchSeries.select().count()
1793 by Canonical.com Patch Queue Manager
SQL changes related to builders and chroots, for Soyuz 1.0 r=stevea,stub
374
8730.4.18 by Michael Nelson
Added IDAS.getIdsForArchitectures() to simplyfy and dry-up D/DS.getBuildRecords().
375
    def getIdsForArchitectures(self, architectures, arch_tag=None):
8730.4.22 by Michael Nelson
Removed IDistroArchSeries.getIdsForArchitectures() from the public interface declaration.
376
        """Filter architectures and return the ids.
377
378
        This method is not exposed via the public interface as it is
379
        used simply to keep trusted code DRY.
380
381
        :param architectures: an iterable of architectures to process.
13636.4.1 by Raphael Badin
Expand IDS checks to the pockets copied, limit IDS checks to the architectures copied.
382
        :param arch_tag: an optional architecture tag or a tag list with
383
            which to filter the results.
8730.4.22 by Michael Nelson
Removed IDistroArchSeries.getIdsForArchitectures() from the public interface declaration.
384
        :return: a list of the ids of the architectures matching arch_tag.
385
        """
8730.4.18 by Michael Nelson
Added IDAS.getIdsForArchitectures() to simplyfy and dry-up D/DS.getBuildRecords().
386
        # If arch_tag was not provided, just return the ids without
387
        # filtering.
388
        if arch_tag is None:
389
            return [arch.id for arch in architectures]
390
        else:
13636.4.11 by Raphael Badin
Use isinstance(arch_tag, (list, tuple) instead of isinstance(arch_tag, collections.Sequence.
391
            if not isinstance(arch_tag, (list, tuple)):
13636.4.1 by Raphael Badin
Expand IDS checks to the pockets copied, limit IDS checks to the architectures copied.
392
                arch_tag = (arch_tag, )
8730.4.18 by Michael Nelson
Added IDAS.getIdsForArchitectures() to simplyfy and dry-up D/DS.getBuildRecords().
393
            return [arch.id for arch in architectures
13636.4.1 by Raphael Badin
Expand IDS checks to the pockets copied, limit IDS checks to the architectures copied.
394
                        if arch.architecturetag in arch_tag]
8730.4.18 by Michael Nelson
Added IDAS.getIdsForArchitectures() to simplyfy and dry-up D/DS.getBuildRecords().
395
3496.1.62 by Celso Providelo
Fixing and redesigning of manage-chroot tool and IPocketChroot
396
1793 by Canonical.com Patch Queue Manager
SQL changes related to builders and chroots, for Soyuz 1.0 r=stevea,stub
397
class PocketChroot(SQLBase):
398
    implements(IPocketChroot)
399
    _table = "PocketChroot"
400
5121.2.6 by Stuart Bishop
Some required code updates
401
    distroarchseries = ForeignKey(dbName='distroarchseries',
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
402
                                   foreignKey='DistroArchSeries',
1793 by Canonical.com Patch Queue Manager
SQL changes related to builders and chroots, for Soyuz 1.0 r=stevea,stub
403
                                   notNull=True)
3496.1.71 by Celso Providelo
fix merged PocketChroot content class
404
405
    pocket = EnumCol(schema=PackagePublishingPocket,
406
                     default=PackagePublishingPocket.RELEASE,
407
                     notNull=True)
408
3500.2.40 by Celso Providelo
Extend the encapsulated API for publishing to DistroRelease/DistroArchRelease via IPublishing.
409
    chroot = ForeignKey(dbName='chroot', foreignKey='LibraryFileAlias')