~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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# Copyright 2010-2011 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""Interface classes for a difference between two distribution series."""

__metaclass__ = type


__all__ = [
    'IDistroSeriesDifference',
    'IDistroSeriesDifferenceAdmin',
    'IDistroSeriesDifferencePublic',
    'IDistroSeriesDifferenceEdit',
    'IDistroSeriesDifferenceSource',
    ]

from lazr.restful.declarations import (
    call_with,
    export_as_webservice_entry,
    export_write_operation,
    exported,
    operation_parameters,
    REQUEST_USER,
    )
from lazr.restful.fields import Reference
from zope.interface import (
    Attribute,
    Interface,
    )
from zope.schema import (
    Bool,
    Choice,
    Int,
    Text,
    TextLine,
    )

from canonical.launchpad import _
from lp.registry.enum import (
    DistroSeriesDifferenceStatus,
    DistroSeriesDifferenceType,
    )
from lp.registry.interfaces.distroseries import IDistroSeries
from lp.registry.interfaces.person import IPerson
from lp.registry.interfaces.sourcepackagename import ISourcePackageName
from lp.soyuz.enums import PackageDiffStatus
from lp.soyuz.interfaces.distroseriessourcepackagerelease import (
    IDistroSeriesSourcePackageRelease,
    )
from lp.soyuz.interfaces.packagediff import IPackageDiff
from lp.soyuz.interfaces.publishing import ISourcePackagePublishingHistory


class IDistroSeriesDifferencePublic(Interface):
    """The public interface for distro series differences."""

    id = Int(title=_('ID'), required=True, readonly=True)

    derived_series = exported(Reference(
        IDistroSeries, title=_("Derived series"), required=True,
        readonly=True, description=_(
            "The distribution series which identifies the derived series "
            "with the difference.")))

    parent_series = exported(Reference(
        IDistroSeries, title=_("Parent series"), required=True,
        readonly=True, description=_(
            "The distribution series which identifies the parent series "
            "with the difference.")))

    source_package_name_id = Int(
        title=u"Source package name id", required=True, readonly=True)
    source_package_name = Reference(
        ISourcePackageName,
        title=_("Source package name"), required=True, readonly=True,
        description=_(
            "The package with a difference between the derived series "
            "and its parent."))

    package_diff = Reference(
        IPackageDiff, title=_("Package diff"), required=False,
        readonly=True, description=_(
            "The most recently generated package diff from the base to the "
            "derived version."))

    package_diff_url = exported(TextLine(
        title=_("Package diff url"), readonly=True, required=False,
        description=_(
            "The url for the diff between the base version and the "
            "derived version.")))

    parent_package_diff = Reference(
        IPackageDiff, title=_("Parent package diff"), required=False,
        readonly=True, description=_(
            "The most recently generated package diff from the base to the "
            "parent version."))

    parent_package_diff_url = exported(TextLine(
        title=_("Parent package diff url"), readonly=True, required=False,
        description=_(
            "The url for the diff between the base version and the "
            "parent version.")))

    package_diff_status = exported(Choice(
        title=_("Package diff status"),
        readonly=True,
        vocabulary=PackageDiffStatus,
        description=_(
            "The status of the diff between the base version and the "
            "derived version.")))

    parent_package_diff_status = exported(Choice(
        title=_("Parent package diff status"),
        readonly=True,
        vocabulary=PackageDiffStatus,
        description=_(
            "The status of the diff between the base version and the "
            "parent version.")))

    status = Choice(
        title=_('Distro series difference status.'),
        description=_('The current status of this difference.'),
        vocabulary=DistroSeriesDifferenceStatus,
        required=True, readonly=True)

    difference_type = Choice(
        title=_('Difference type'),
        description=_('The type of difference for this package.'),
        vocabulary=DistroSeriesDifferenceType,
        required=True, readonly=True)

    source_package_release = Reference(
        IDistroSeriesSourcePackageRelease,
        title=_("Derived source pub"), readonly=True,
        description=_(
            "The published version in the derived series with version "
            "source_version."))

    parent_source_package_release = Reference(
        IDistroSeriesSourcePackageRelease,
        title=_("Parent source pub"), readonly=True,
        description=_(
            "The published version in the derived series with version "
            "parent_source_version."))

    source_pub = Reference(
        ISourcePackagePublishingHistory,
        title=_("Latest derived source pub"), readonly=True,
        description=_(
            "The most recent published version in the derived series."))

    source_version = TextLine(
        title=_("Source version"), readonly=True,
        description=_(
            "The version of the most recent source publishing in the "
            "derived series."))

    parent_source_pub = Reference(
        ISourcePackagePublishingHistory,
        title=_("Latest parent source pub"), readonly=True,
        description=_(
            "The most recent published version in the parent series."))

    parent_source_version = TextLine(
        title=_("Parent source version"), readonly=True,
        description=_(
            "The version of the most recent source publishing in the "
            "parent series."))

    base_version = TextLine(
        title=_("Base version"), readonly=True,
        description=_(
            "The common base version of the package for differences "
            "with different versions in the parent and derived series."))

    base_source_pub = Reference(
        ISourcePackagePublishingHistory,
        title=_("Base source pub"), readonly=True,
        description=_(
            "The common base version published in the parent or the "
            "derived series."))

    owner = Reference(
        IPerson, title=_("Owning team of the derived series"), readonly=True,
        description=_(
            "This attribute mirrors the owner of the derived series."))

    title = TextLine(
        title=_("Title"), readonly=True, required=False, description=_(
            "A human-readable name describing this difference."))

    packagesets = Attribute("The packagesets for this source package in the "
                            "derived series.")

    parent_packagesets = Attribute("The packagesets for this source package "
                                   "in the parent series.")

    base_distro_source_package_release = Attribute(
        "The DistributionSourcePackageRelease object for the source release "
        "in the parent distribution.")

    def update(manual=False):
        """Checks that difference type and status matches current publishings.

        If the record is updated, a relevant comment is added.

        If there is no longer a difference (ie. the versions are
        the same) then the status is updated to RESOLVED.

        :param manual: Boolean, True if this is a user-requested change.
            This overrides auto-blacklisting.
        :return: True if the record was updated, False otherwise.
        """

    latest_comment = Reference(
        Interface,  # IDistroSeriesDifferenceComment
        title=_("The latest comment"),
        readonly=True)

    def getComments():
        """Return a result set of the comments for this difference."""


class IDistroSeriesDifferenceEdit(Interface):
    """Difference attributes requiring launchpad.Edit."""

    @call_with(commenter=REQUEST_USER)
    @operation_parameters(
        comment=Text(title=_("Comment text"), required=True))
    @export_write_operation()
    def addComment(commenter, comment):
        """Add a comment on this difference."""

    @call_with(requestor=REQUEST_USER)
    @export_write_operation()
    def requestPackageDiffs(requestor):
        """Requests IPackageDiffs for the derived and parent version.

        :raises DistroSeriesDifferenceError: When package diffs
            cannot be requested.
        """


class IDistroSeriesDifferenceAdmin(Interface):
    """Difference attributes requiring launchpad.Admin."""

    @operation_parameters(
        all=Bool(title=_("All"), required=False))
    @export_write_operation()
    def blacklist(all=False):
        """Blacklist this version or all versions of this source package.

        :param all: indicates whether all versions of this package should
            be blacklisted or just the current (default).
        """

    @export_write_operation()
    def unblacklist():
        """Removes this difference from the blacklist.

        The status will be updated based on the versions.
        """


class IDistroSeriesDifference(IDistroSeriesDifferencePublic,
                              IDistroSeriesDifferenceEdit,
                              IDistroSeriesDifferenceAdmin):
    """An interface for a package difference between two distroseries."""
    export_as_webservice_entry()


class IDistroSeriesDifferenceSource(Interface):
    """A utility of this interface can be used to create differences."""

    def new(derived_series, source_package_name, parent_series=None):
        """Create an `IDistroSeriesDifference`.

        :param derived_series: The distribution series which was derived
            from a parent. If a series without a parent is passed an
            exception is raised.
        :type derived_series: `IDistroSeries`.
        :param source_package_name: A source package name identifying the
            package with a difference.
        :type source_package_name: `ISourcePackageName`.
        :param parent_series: The distribution series which has the derived
            series as a child. If there is only one parent, it does not need
            to be specified.
        :type parent_series: `IDistroSeries`.
        :raises NotADerivedSeriesError: When the passed distro series
            is not a derived series.
        :return: A new `DistroSeriesDifference` object.
        """

    def getForDistroSeries(
        distro_series,
        difference_type=None,
        source_package_name_filter=None,
        status=None,
        child_version_higher=False,
        parent_series=None,
        packagesets=None):
        """Return differences for the derived distro series sorted by
        package name.

        :param distro_series: The derived distribution series which is to be
            searched for differences.
        :type distro_series: `IDistroSeries`.
        :param difference_type: The type of difference to include in the
            results.
        :type difference_type: `DistroSeriesDifferenceType`.
        :param source_package_name_filter: Name of a source package.  If
            given, restricts the search to this package.
        :type source_package_name_filter: unicode.
        :param status: Only differences matching the status(es) will be
            included.
        :type status: `DistroSeriesDifferenceStatus`.
        :param child_version_higher: Only differences for which the child's
            version is higher than the parent's version will be included.
        :type child_version_higher: bool.
        :param parent_series: The parent series to consider. Consider all
            parent series if this parameter is None.
        :type distro_series: `IDistroSeries`.
        :param packagesets: Optional iterable of `Packageset` to filter by.
        :return: A result set of `IDistroSeriesDifference`.
        """

    def getByDistroSeriesNameAndParentSeries(distro_series,
                                             source_package_name,
                                             parent_series):
        """Returns a single difference matching the series, name and parent
        series.

        :param distro_series: The derived distribution series which is to be
            searched for differences.
        :type distro_series: `IDistroSeries`.
        :param source_package_name: The name of the package difference.
        :type source_package_name: unicode.
        :param parent_series: The parent distribution series of the package
        difference.
        :type distro_series: `IDistroSeries`.
        """

    def getSimpleUpgrades(distro_series):
        """Find pending upgrades that can be performed mindlessly.

        These are `DistroSeriesDifferences` where the parent has been
        updated and the child still has the old version, unchanged.

        Blacklisted items are excluded.
        """