~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# Copyright 2009 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

# pylint: disable-msg=E0611,W0212

"""Classes to represent binary package releases in a
distributionarchitecture release."""

__metaclass__ = type

__all__ = [
    'DistroArchSeriesBinaryPackageRelease',
    ]

from zope.interface import implements

from canonical.database.sqlbase import sqlvalues
from lp.soyuz.enums import PackagePublishingStatus
from lp.soyuz.interfaces.distroarchseriesbinarypackagerelease import (
    IDistroArchSeriesBinaryPackageRelease,
    )
from lp.soyuz.model.distributionsourcepackagerelease import (
    DistributionSourcePackageRelease,
    )
from lp.soyuz.model.publishing import BinaryPackagePublishingHistory


class DistroArchSeriesBinaryPackageRelease:

    implements(IDistroArchSeriesBinaryPackageRelease)

    def __init__(self, distroarchseries, binarypackagerelease):
        self.distroarchseries = distroarchseries
        self.binarypackagerelease = binarypackagerelease

    @property
    def name(self):
        """See `IDistroArchSeriesBinaryPackageRelease`."""
        return self.binarypackagerelease.binarypackagename.name

    @property
    def version(self):
        """See `IDistroArchSeriesBinaryPackageRelease`."""
        return self.binarypackagerelease.version

    @property
    def distroseries(self):
        """See `IDistroArchSeriesBinaryPackageRelease`."""
        return self.distroarchseries.distroseries

    @property
    def distribution(self):
        """See `IDistroArchSeriesBinaryPackageRelease`."""
        return self.distroarchseries.distroseries.distribution

    @property
    def displayname(self):
        """See `IDistroArchSeriesBinaryPackageRelease`."""
        return '%s %s' % (self.name, self.version)

    @property
    def title(self):
        """See `IDistroArchSeriesBinaryPackageRelease`."""
        return '%s %s (%s binary) in %s %s' % (
            self.name, self.version, self.distroarchseries.architecturetag,
            self.distribution.name, self.distroseries.name)

    @property
    def distributionsourcepackagerelease(self):
        """See `IDistroArchSeriesBinaryPackageRelease`."""
        return DistributionSourcePackageRelease(
            self.distribution,
            self.build.source_package_release)

    @property
    def distroarchseriesbinarypackage(self):
        """See `IDistroArchSeriesBinaryPackage`."""
        return self.distroarchseries.getBinaryPackage(
            self.binarypackagename)

    # XXX: kiko, 2006-02-01: I'd like to rename this to
    # current_published_publishing_record, because that's what it
    # returns, but I don't want to do that right now.
    @property
    def current_publishing_record(self):
        """See `IDistroArchSeriesBinaryPackageRelease`."""
        status = [
            PackagePublishingStatus.PENDING,
            PackagePublishingStatus.PUBLISHED]
        record = self._latest_publishing_record(status=status)
        return record

# XXX cprov 20071026: heavy queries should be moved near to the related
# content classes in order to be better maintained. In this specific case
# the publishing queries should live in publishing.py.
    def _latest_publishing_record(self, status=None):
        query = """
            binarypackagerelease = %s AND
            distroarchseries = %s AND
            archive IN %s
        """ % sqlvalues(self.binarypackagerelease, self.distroarchseries,
                        self.distribution.all_distro_archive_ids)

        if status is not None:
            if not isinstance(status, list):
                status = [status]
            query += " AND status IN %s" % sqlvalues(status)

        return BinaryPackagePublishingHistory.selectFirst(
            query, orderBy=['-datecreated', '-id'])

    @property
    def publishing_history(self):
        """See `IDistroArchSeriesBinaryPackage`."""
        return BinaryPackagePublishingHistory.select("""
            distroarchseries = %s AND
            archive IN %s AND
            binarypackagerelease = %s
            """ % sqlvalues(
                    self.distroarchseries,
                    self.distribution.all_distro_archive_ids,
                    self.binarypackagerelease),
            orderBy=['-datecreated', '-id'])

    @property
    def pocket(self):
        """See `IDistroArchSeriesBinaryPackageRelease`."""
        pub = self._latest_publishing_record()
        if pub is None:
            return None
        return pub.pocket

    @property
    def status(self):
        """See `IDistroArchSeriesBinaryPackageRelease`."""
        pub = self._latest_publishing_record()
        if pub is None:
            return None
        return pub.status

    @property
    def section(self):
        """See `IDistroArchSeriesBinaryPackageRelease`."""
        pub = self._latest_publishing_record()
        if pub is None:
            return None
        return pub.section

    @property
    def component(self):
        """See `IDistroArchSeriesBinaryPackageRelease`."""
        pub = self._latest_publishing_record()
        if pub is None:
            return None
        return pub.component

    @property
    def priority(self):
        """See `IDistroArchSeriesBinaryPackageRelease`."""
        pub = self._latest_publishing_record()
        if pub is None:
            return None
        return pub.priority

    # map the BinaryPackageRelease attributes up to this class so it
    # responds to the same interface

    @property
    def binarypackagename(self):
        """See `IBinaryPackageRelease`."""
        return self.binarypackagerelease.binarypackagename

    @property
    def summary(self):
        """See `IBinaryPackageRelease`."""
        return self.binarypackagerelease.summary

    @property
    def description(self):
        """See `IBinaryPackageRelease`."""
        return self.binarypackagerelease.description

    @property
    def build(self):
        """See `IBinaryPackageRelease`."""
        return self.binarypackagerelease.build

    @property
    def binpackageformat(self):
        """See `IPackageRelease`."""
        return self.binarypackagerelease.binpackageformat

    @property
    def shlibdeps(self):
        """See `IBinaryPackageRelease`."""
        return self.binarypackagerelease.shlibdeps

    @property
    def depends(self):
        """See `IBinaryPackageRelease`."""
        return self.binarypackagerelease.depends

    @property
    def recommends(self):
        """See `IBinaryPackageRelease`."""
        return self.binarypackagerelease.recommends

    @property
    def replaces(self):
        """See `IBinaryPackageRelease`."""
        return self.binarypackagerelease.replaces

    @property
    def conflicts(self):
        """See `IBinaryPackageRelease`."""
        return self.binarypackagerelease.conflicts

    @property
    def provides(self):
        """See `IBinaryPackageRelease`."""
        return self.binarypackagerelease.provides

    @property
    def suggests(self):
        """See `IBinaryPackageRelease`."""
        return self.binarypackagerelease.suggests

    @property
    def essential(self):
        """See `IBinaryPackageRelease`."""
        return self.binarypackagerelease.essential

    @property
    def installedsize(self):
        """See `IBinaryPackageRelease`."""
        return self.binarypackagerelease.installedsize

    @property
    def architecturespecific(self):
        """See `IBinaryPackageRelease`."""
        return self.binarypackagerelease.architecturespecific

    @property
    def datecreated(self):
        """See `IBinaryPackageRelease`."""
        return self.binarypackagerelease.datecreated

    @property
    def files(self):
        """See `IBinaryPackageRelease`."""
        return self.binarypackagerelease.files