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
|
# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
# pylint: disable-msg=E0211,E0213
"""Interfaces related to package-diff system."""
__metaclass__ = type
__all__ = [
'IPackageDiff',
'IPackageDiffSet',
'PackageDiffAlreadyRequested',
]
import httplib
from lazr.restful.declarations import error_status
from zope.interface import (
Attribute,
Interface,
)
from zope.schema import (
Choice,
Datetime,
Object,
)
from canonical.launchpad import _
from canonical.launchpad.interfaces.librarian import ILibraryFileAlias
from lp.soyuz.enums import PackageDiffStatus
@error_status(httplib.BAD_REQUEST)
class PackageDiffRequestException(Exception):
"""Base class for package diff request errors."""
class PackageDiffAlreadyRequested(PackageDiffRequestException):
"""Raised on attempts to request an already recorded diff request. """
class IPackageDiff(Interface):
"""Package diff request and storage.
See `doc/package-diff.txt` for details about the attributes.
"""
id = Attribute("The PackageDiff unique number.")
from_source = Attribute(_("The base ISourcePackageRelease."))
to_source = Attribute(_("The target ISourcePackageRelease."))
date_requested = Datetime(
title=_('Date Requested'), required=True, readonly=True)
requester = Choice(
title=_('User'),
required=True,
vocabulary='ValidPerson',
description=_("The person requesting the diff."))
date_fulfilled = Datetime(
title=_('Date Fulfilled'), required=False)
diff_content = Object(
schema=ILibraryFileAlias,
title=_("The ILibraryFileAlias containing the diff."),
required=False)
status = Choice(
title=_('Status'),
description=_('The status of this package diff request.'),
vocabulary='PackageDiffStatus',
required=False, default=PackageDiffStatus.PENDING,
)
title = Attribute("The Package diff title.")
private = Attribute(
"Whether or not the package diff content is private. "
"A package diff is considered private when 'to_source' was "
"originally uploaded to a private archive.")
def performDiff():
"""Performs a diff between two packages."""
class IPackageDiffSet(Interface):
"""The set of `PackageDiff`."""
def __iter__():
"""Iterate over all `PackageDiff`."""
def get(diff_id):
"""Retrieve a `PackageDiff` for the given id."""
def getPendingDiffs(limit=None):
"""Return all pending `PackageDiff` records.
:param limit: optional results limitation.
:return a `SelectResult` ordered by id respecting the given limit.
"""
def getDiffsToReleases(sprs, preload_for_display=False):
"""Return all diffs that targetting a set of source package releases.
:param sprs: a sequence of `SourcePackageRelease` objects.
:param preload_for_display: True if all the attributes needed for
link rendering should be preloaded.
:return a `ResultSet` ordered by `SourcePackageRelease` ID and
then diff request date in descending order. If sprs is empty,
EmptyResultSet is returned.
"""
def getDiffBetweenReleases(from_spr, to_spr):
"""Return the diff that is targetted to the two SPRs.
:param from_spr: a `SourcePackageRelease` object.
:param to_spr: a `SourcePackageRelease` object.
:return a `PackageDiff` or None.
"""
|