~launchpad-pqm/launchpad/devel

13760.1.1 by Jeroen Vermeulen
Fixing up a few broken utilities, and lint.
1
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
8687.15.15 by Karl Fogel
Add the copyright header block to files under lib/lp/bugs/.
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
4983.1.1 by Curtis Hovey
Added lint exceptions to __init__.py and interface/*.py.
4
# pylint: disable-msg=E0211,E0213
1634 by Canonical.com Patch Queue Manager
implement most of https://wiki.launchpad.canonical.com/BugEditNotifications. still a couple small asthetic nuances to clarify.
5
2068 by Canonical.com Patch Queue Manager
[r=SteveA/trivial] import fascism, kill translationeffort, kill sshkey browser code, add __all__s to interfaces, other cleanings-up
6
"""Bug watch interfaces."""
7
1634 by Canonical.com Patch Queue Manager
implement most of https://wiki.launchpad.canonical.com/BugEditNotifications. still a couple small asthetic nuances to clarify.
8
__metaclass__ = type
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
9
2068 by Canonical.com Patch Queue Manager
[r=SteveA/trivial] import fascism, kill translationeffort, kill sshkey browser code, add __all__s to interfaces, other cleanings-up
10
__all__ = [
7675.625.2 by Graham Binns
The BugWatchScheduler now takes account of the fact that BugWatchActivityStatus can indicate success as well as failure.
11
    'BUG_WATCH_ACTIVITY_SUCCESS_STATUSES',
7675.589.1 by Graham Binns
Renamed BugWatchErrorType to BugWatchActivityStatus.
12
    'BugWatchActivityStatus',
7675.640.4 by Graham Binns
Added IBugWatch.setNextCheck().
13
    'BugWatchCannotBeRescheduled',
2068 by Canonical.com Patch Queue Manager
[r=SteveA/trivial] import fascism, kill translationeffort, kill sshkey browser code, add __all__s to interfaces, other cleanings-up
14
    'IBugWatch',
7675.586.8 by Graham Binns
Added tests.
15
    'IBugWatchActivity',
2068 by Canonical.com Patch Queue Manager
[r=SteveA/trivial] import fascism, kill translationeffort, kill sshkey browser code, add __all__s to interfaces, other cleanings-up
16
    'IBugWatchSet',
3691.174.2 by Bjorn Tillenius
add IBugWatchSet.getBugTrackerAndBug.
17
    'NoBugTrackerFound',
3691.174.22 by Bjorn Tillenius
review comments.
18
    'UnrecognizedBugTrackerURL',
2068 by Canonical.com Patch Queue Manager
[r=SteveA/trivial] import fascism, kill translationeffort, kill sshkey browser code, add __all__s to interfaces, other cleanings-up
19
    ]
20
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
21
from lazr.enum import (
22
    DBEnumeratedType,
23
    DBItem,
24
    )
25
from lazr.restful.declarations import (
26
    export_as_webservice_entry,
27
    exported,
28
    )
29
from lazr.restful.fields import (
30
    CollectionField,
31
    Reference,
32
    ReferenceChoice,
33
    )
34
from zope.interface import (
35
    Attribute,
36
    Interface,
37
    )
38
from zope.schema import (
39
    Choice,
40
    Datetime,
41
    Int,
42
    Text,
43
    TextLine,
44
    )
3496.2.12 by Brad Bollenbach
last bits of IBug.date_last_updated
45
14600.1.12 by Curtis Hovey
Move i18n to lp.
46
from lp import _
14612.2.1 by William Grant
format-imports on lib/. So many imports.
47
from lp.bugs.interfaces.bugtracker import IBugTracker
14560.2.23 by Curtis Hovey
Moved IHasBug to its own module.
48
from lp.bugs.interfaces.hasbug import IHasBug
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
49
from lp.services.fields import StrippedTextLine
6484.8.1 by Gavin Panella
Annotate IBugWatch for webservices.
50
4948.1.1 by Graham Binns
Added a DBEnumeratedType, BugWatchErrorType to the BugWatch interface.
51
7675.589.1 by Graham Binns
Renamed BugWatchErrorType to BugWatchActivityStatus.
52
class BugWatchActivityStatus(DBEnumeratedType):
4948.1.1 by Graham Binns
Added a DBEnumeratedType, BugWatchErrorType to the BugWatch interface.
53
    """An enumeration of possible BugWatch errors."""
54
5406.1.3 by Graham Binns
Added an UNKNOWN BugWatchErrorType.
55
    UNKNOWN = DBItem(999, """
56
        Unknown
57
58
        Launchpad encountered an unexpected error when trying to
59
        retrieve the bug from the remote server.
60
        """)
61
4948.1.34 by Graham Binns
Renamed BugWatchErrorType items to include underscores for readability.
62
    BUG_NOT_FOUND = DBItem(1, """
4948.1.11 by Graham Binns
It helps, people, if your Test classes actually implement everything they need to implement to not break stupidly.
63
        Bug Not Found
4948.1.1 by Graham Binns
Added a DBEnumeratedType, BugWatchErrorType to the BugWatch interface.
64
65
        Launchpad could not find the specified bug on the remote server.
66
        """)
67
4948.1.34 by Graham Binns
Renamed BugWatchErrorType items to include underscores for readability.
68
    CONNECTION_ERROR = DBItem(2, """
4948.1.6 by Graham Binns
Refactored BugWatch.lasterror mutation into components.externalbugtracker. It doesn't belong in scripts.checkwatches unless absolutely necessary since the errors don't occur at that level.
69
        Connection Error
70
71
        Launchpad was unable to connect to the remote server.
72
        """)
73
4948.1.34 by Graham Binns
Renamed BugWatchErrorType items to include underscores for readability.
74
    INVALID_BUG_ID = DBItem(3, """
4948.1.1 by Graham Binns
Added a DBEnumeratedType, BugWatchErrorType to the BugWatch interface.
75
        Invalid Bug ID
76
77
        The specified bug ID is not valid.
78
        """)
79
4948.1.6 by Graham Binns
Refactored BugWatch.lasterror mutation into components.externalbugtracker. It doesn't belong in scripts.checkwatches unless absolutely necessary since the errors don't occur at that level.
80
    TIMEOUT = DBItem(4, """
81
        Timeout
82
83
        Launchpad encountered a timeout when trying to connect to the
84
        remote server and was unable to retrieve the bug's status.
85
        """)
86
4948.1.34 by Graham Binns
Renamed BugWatchErrorType items to include underscores for readability.
87
    UNPARSABLE_BUG = DBItem(5, """
4948.1.1 by Graham Binns
Added a DBEnumeratedType, BugWatchErrorType to the BugWatch interface.
88
        Unparsable Bug
89
90
        Launchpad could not extract a status from the data it received
91
        from the remote server.
92
        """)
93
4948.1.34 by Graham Binns
Renamed BugWatchErrorType items to include underscores for readability.
94
    UNPARSABLE_BUG_TRACKER = DBItem(6, """
4948.1.6 by Graham Binns
Refactored BugWatch.lasterror mutation into components.externalbugtracker. It doesn't belong in scripts.checkwatches unless absolutely necessary since the errors don't occur at that level.
95
        Unparsable Bug Tracker Version
96
6484.8.1 by Gavin Panella
Annotate IBugWatch for webservices.
97
        Launchpad could not determine the version of the bug tracker
4948.1.6 by Graham Binns
Refactored BugWatch.lasterror mutation into components.externalbugtracker. It doesn't belong in scripts.checkwatches unless absolutely necessary since the errors don't occur at that level.
98
        software running on the remote server.
99
        """)
100
4948.1.34 by Graham Binns
Renamed BugWatchErrorType items to include underscores for readability.
101
    UNSUPPORTED_BUG_TRACKER = DBItem(7, """
5513.2.2 by Graham Binns
Added functionality requried to fix this bug.
102
        Unsupported Bugtracker
4948.1.6 by Graham Binns
Refactored BugWatch.lasterror mutation into components.externalbugtracker. It doesn't belong in scripts.checkwatches unless absolutely necessary since the errors don't occur at that level.
103
5513.2.2 by Graham Binns
Added functionality requried to fix this bug.
104
        The remote server is using bug tracker software which Launchpad
105
        does not currently support.
4948.1.6 by Graham Binns
Refactored BugWatch.lasterror mutation into components.externalbugtracker. It doesn't belong in scripts.checkwatches unless absolutely necessary since the errors don't occur at that level.
106
        """)
107
6204.3.3 by Graham Binns
Added PrivateRemoteBug handling.
108
    PRIVATE_REMOTE_BUG = DBItem(8, """
109
        Private Remote Bug
110
111
        The bug is marked as private on the remote bug tracker.
112
        Launchpad cannot import the status of private remote bugs.
113
        """)
114
7675.625.1 by Graham Binns
Added a default SYNC_SUCCEDED value for BugWatchActivity.
115
    SYNC_SUCCEEDED = DBItem(9, """
116
        Synchronisation succeeded
117
7675.637.1 by Graham Binns
Added extra BugWatchActivityStatus failure states.
118
        The remote bug's status was successfully synchronized to Launchpad.
119
        """)
120
121
    COMMENT_IMPORT_FAILED = DBItem(10, """
122
        Unable to import comments
123
124
        The remote bug's status was synchronized successfully but
125
        comments could not be imported from the remote bug.
126
        """)
127
128
    COMMENT_PUSH_FAILED = DBItem(11, """
129
        Unable to push comments
130
131
        The remote bug's status was synchronized successfully and
132
        its comments were successfully imported but Launchpad was unable
133
        to push comments back to the remote bug.
134
        """)
135
136
    BACKLINK_FAILED = DBItem(12, """
137
        Unable to set link remote bug to Launchpad
138
139
        The remote bug's status and comments were synchronized
140
        sucessfully with Launchpad but Launchpad was unable to set the
141
        remote bug's link back to the relevant Launchpad bug.
7675.625.1 by Graham Binns
Added a default SYNC_SUCCEDED value for BugWatchActivity.
142
        """)
143
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
144
7675.625.2 by Graham Binns
The BugWatchScheduler now takes account of the fact that BugWatchActivityStatus can indicate success as well as failure.
145
# The set of BugWatchActivityStatuses that are considered to indicate
146
# success.
147
BUG_WATCH_ACTIVITY_SUCCESS_STATUSES = [
148
    BugWatchActivityStatus.SYNC_SUCCEEDED,
149
    ]
150
151
3496.2.12 by Brad Bollenbach
last bits of IBug.date_last_updated
152
class IBugWatch(IHasBug):
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
153
    """A bug on a remote system."""
6484.8.1 by Gavin Panella
Annotate IBugWatch for webservices.
154
    export_as_webservice_entry()
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
155
6484.8.11 by Gavin Panella
Don't expose IBugWatch.id.
156
    id = Int(title=_('ID'), required=True, readonly=True)
13760.1.1 by Jeroen Vermeulen
Fixing up a few broken utilities, and lint.
157
158
    # Actually refers to Bug; redefined in bug.py.
6484.8.1 by Gavin Panella
Annotate IBugWatch for webservices.
159
    bug = exported(
13760.1.1 by Jeroen Vermeulen
Fixing up a few broken utilities, and lint.
160
        Reference(
161
            title=_('Bug'), schema=Interface, required=True, readonly=True))
6484.9.2 by Gavin Panella
Expose IBugTracker, some tests, and link from IBugWatch.
162
    bugtracker = exported(
6655.3.2 by Gavin Panella
Corrections to IBugWatch as suggested by flacoste. Also had to switch the order of resolving circular imports of IBugWatch and IBugTracker due to a weird bug that leonardr is investigating.
163
        ReferenceChoice(
6484.9.2 by Gavin Panella
Expose IBugTracker, some tests, and link from IBugWatch.
164
            title=_('Bug System'), required=True,
6655.3.2 by Gavin Panella
Corrections to IBugWatch as suggested by flacoste. Also had to switch the order of resolving circular imports of IBugWatch and IBugTracker due to a weird bug that leonardr is investigating.
165
            schema=IBugTracker, vocabulary='BugTracker',
166
            description=_(
6484.9.2 by Gavin Panella
Expose IBugTracker, some tests, and link from IBugWatch.
167
                "You can register new bug trackers from the Launchpad "
168
                "Bugs home page.")),
169
        exported_as='bug_tracker')
6484.8.1 by Gavin Panella
Annotate IBugWatch for webservices.
170
    remotebug = exported(
171
        StrippedTextLine(
172
            title=_('Remote Bug'), required=True,
6484.9.2 by Gavin Panella
Expose IBugTracker, some tests, and link from IBugWatch.
173
            readonly=False, description=_(
174
                "The bug number of this bug in the remote bug tracker.")),
6484.8.1 by Gavin Panella
Annotate IBugWatch for webservices.
175
        exported_as='remote_bug')
176
    remotestatus = exported(
6484.8.2 by Gavin Panella
Set proper permissions on IBugWatch, and so unset readonly on a few attributes.
177
        TextLine(title=_('Remote Status')),
6484.8.1 by Gavin Panella
Annotate IBugWatch for webservices.
178
        exported_as='remote_status')
179
    remote_importance = exported(
6484.8.2 by Gavin Panella
Set proper permissions on IBugWatch, and so unset readonly on a few attributes.
180
        TextLine(title=_('Remote Importance')))
6484.8.1 by Gavin Panella
Annotate IBugWatch for webservices.
181
    lastchanged = exported(
6484.8.2 by Gavin Panella
Set proper permissions on IBugWatch, and so unset readonly on a few attributes.
182
        Datetime(title=_('Last Changed')),
6484.8.1 by Gavin Panella
Annotate IBugWatch for webservices.
183
        exported_as='date_last_changed')
184
    lastchecked = exported(
6484.8.2 by Gavin Panella
Set proper permissions on IBugWatch, and so unset readonly on a few attributes.
185
        Datetime(title=_('Last Checked')),
6484.8.1 by Gavin Panella
Annotate IBugWatch for webservices.
186
        exported_as='date_last_checked')
187
    last_error_type = exported(
7675.589.1 by Graham Binns
Renamed BugWatchErrorType to BugWatchActivityStatus.
188
        Choice(title=_('Last Error Type'), vocabulary=BugWatchActivityStatus))
6484.8.1 by Gavin Panella
Annotate IBugWatch for webservices.
189
    datecreated = exported(
190
        Datetime(title=_('Date Created'), required=True, readonly=True),
191
        exported_as='date_created')
192
    owner = exported(
193
        Reference(title=_('Owner'), required=True,
10094.3.3 by Markus Korn
Next step to make IPerson an IHasBugs:
194
                  readonly=True, schema=Interface))
7675.586.8 by Graham Binns
Added tests.
195
    activity = Attribute('The activity history of this BugWatch.')
7675.595.2 by Graham Binns
Added next_check attribute to BugWatch.
196
    next_check = exported(
197
        Datetime(title=_('Next Check')),
198
        exported_as='date_next_checked')
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
199
6484.8.13 by Gavin Panella
Post-review changes.
200
    # Useful joins.
6484.8.1 by Gavin Panella
Annotate IBugWatch for webservices.
201
    bugtasks = exported(
202
        CollectionField(
203
            description=_(
204
                'The tasks which this watch will affect. '
205
                'In Launchpad, a bug watch can be linked to one or more '
206
                'tasks, and if it is linked and we notice a status change '
207
                'in the watched bug then we will try to update the '
208
                'Launchpad bug task accordingly.'),
7014.3.3 by Bjorn Tillenius
fix lint warning.
209
            # value_type is redefined in bugtask.py, to use the right
210
            # interface.
211
            value_type=Reference(schema=Interface,)),
6750.1.1 by Leonard Richardson
Initial implementation.
212
            exported_as='bug_tasks')
1896 by Canonical.com Patch Queue Manager
allow for linking a bugtask to a bugwatch [r=spiv, dba r=stub]
213
6484.8.13 by Gavin Panella
Post-review changes.
214
    # Properties.
2048 by Canonical.com Patch Queue Manager
debbugssync, hct enabling, and ui fixes. r=jamesh
215
    needscheck = Attribute("A True or False indicator of whether or not "
216
        "this watch needs to be synchronised. The algorithm used considers "
217
        "the severity of the bug, as well as the activity on the bug, to "
3270.3.34 by Matthew Paul Thomas
Drops priority from the code.
218
        "ensure that we spend most effort on high-importance and "
219
        "high-activity bugs.")
2048 by Canonical.com Patch Queue Manager
debbugssync, hct enabling, and ui fixes. r=jamesh
220
7238.4.3 by Graham Binns
BugWatch.has_unpushed_comments -> BugWatch.unpushed_comments.
221
    unpushed_comments = Attribute(
222
        "A set of comments on this BugWatch that need to be pushed to "
223
        "the remote bug tracker.")
7238.4.2 by Graham Binns
BugWatch now has a has_unpushed_comments property.
224
6484.8.13 by Gavin Panella
Post-review changes.
225
    # Required for Launchpad pages.
6484.8.1 by Gavin Panella
Annotate IBugWatch for webservices.
226
    title = exported(
227
        Text(title=_('Bug watch title'), readonly=True))
1382 by Canonical.com Patch Queue Manager
new page layout
228
6484.8.1 by Gavin Panella
Annotate IBugWatch for webservices.
229
    url = exported(
230
        Text(title=_('The URL at which to view the remote bug.'),
231
             readonly=True))
2048 by Canonical.com Patch Queue Manager
debbugssync, hct enabling, and ui fixes. r=jamesh
232
7675.640.3 by Graham Binns
BugWatch.can_be_rescheduled now works on the same basis as BugWatchActivityPortletView.userCanReschedule() did before it.
233
    can_be_rescheduled = Attribute(
234
        "A True or False indicator of whether or not this watch can be "
235
        "rescheduled.")
236
5272.2.8 by Graham Binns
Added updateImportance() method to bug watches.
237
    def updateImportance(remote_importance, malone_importance):
238
        """Update the importance of the bug watch and any linked bug task.
239
240
        The lastchanged attribute gets set to the current time.
241
        """
242
3063.2.23 by Bjorn Tillenius
initial support for syncing bugwatches and bugtasks.
243
    def updateStatus(remote_status, malone_status):
244
        """Update the status of the bug watch and any linked bug task.
245
246
        The lastchanged attribute gets set to the current time.
247
        """
248
3691.319.2 by Bjorn Tillenius
make it possible to delete a bug watch from the edit page.
249
    def destroySelf():
250
        """Delete this bug watch."""
251
5626.4.3 by Graham Binns
Added tests for BugWatch comment import functionality.
252
    def hasComment(comment_id):
253
        """Return True if a comment has been imported for the BugWatch.
254
255
        If the comment has not been imported, return False.
256
257
        :param comment_id: The remote ID of the comment.
258
        """
259
260
    def addComment(comment_id, message):
261
        """Link and imported comment to the BugWatch.
262
263
        :param comment_id: The remote ID of the comment.
264
265
        :param message: The imported comment as a Launchpad Message object.
266
        """
267
6995.1.1 by Bjorn Tillenius
add BugWatch.getImportedBugMessages.
268
    def getImportedBugMessages():
269
        """Return all the `IBugMessage`s that have been imported."""
270
7675.586.8 by Graham Binns
Added tests.
271
    def addActivity(result=None, message=None, oops_id=None):
272
        """Add an `IBugWatchActivity` record for this BugWatch."""
273
7675.640.4 by Graham Binns
Added IBugWatch.setNextCheck().
274
    def setNextCheck(next_check):
275
        """Set the next_check time of the watch.
276
277
        :raises: `BugWatchCannotBeRescheduled` if
278
                 `IBugWatch.can_be_rescheduled` is False.
279
        """
11435.4.1 by Graham Binns
Added tests and implementation for BugWatch.reset().
280
    def reset():
281
        """Completely reset the watch.
282
283
        When called, the following attributes are reset:
284
         * last_error_type -> None
285
         * lastchanged -> None
286
         * lastchecked -> None
287
         * nextcheck -> now
288
         * remoteimportance -> None
289
         * remotestatus -> None
290
        """
7675.640.4 by Graham Binns
Added IBugWatch.setNextCheck().
291
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
292
6655.3.2 by Gavin Panella
Corrections to IBugWatch as suggested by flacoste. Also had to switch the order of resolving circular imports of IBugWatch and IBugTracker due to a weird bug that leonardr is investigating.
293
# Defined here because of circular imports.
294
IBugTracker['watches'].value_type.schema = IBugWatch
295
296
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
297
class IBugWatchSet(Interface):
6484.8.13 by Gavin Panella
Post-review changes.
298
    """The set of `IBugWatch`es."""
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
299
9186.2.11 by Gavin Panella
Reinstate BugSetBase; its removal created too much follow-on work for right now.
300
    bug = Int(title=_("Bug id"), readonly=True)
1382 by Canonical.com Patch Queue Manager
new page layout
301
    title = Attribute('Title')
302
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
303
    def __getitem__(key):
304
        """Get a BugWatch"""
305
9186.2.11 by Gavin Panella
Reinstate BugSetBase; its removal created too much follow-on work for right now.
306
    def __iter__():
307
        """Iterate through BugWatches for a given bug."""
308
1634 by Canonical.com Patch Queue Manager
implement most of https://wiki.launchpad.canonical.com/BugEditNotifications. still a couple small asthetic nuances to clarify.
309
    def get(id):
310
        """Get an IBugWatch by its ID.
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
311
2976.10.15 by Stuart Bishop
zope.exceptions.NotFoundError is deprecated
312
        Raise a NotFoundError if there is no IBugWatch
1634 by Canonical.com Patch Queue Manager
implement most of https://wiki.launchpad.canonical.com/BugEditNotifications. still a couple small asthetic nuances to clarify.
313
        matching the given id.
314
        """
2048 by Canonical.com Patch Queue Manager
debbugssync, hct enabling, and ui fixes. r=jamesh
315
2458 by Canonical.com Patch Queue Manager
[r=kiko] remove more dirty database imports
316
    def search():
317
        """Search through all the IBugWatches in the system."""
318
2048 by Canonical.com Patch Queue Manager
debbugssync, hct enabling, and ui fixes. r=jamesh
319
    def fromText(text, bug, owner):
320
        """Create one or more BugWatch's by analysing the given text. This
321
        will look for reference to known or new bug tracking instances and
322
        create the relevant watches. It returns a (possibly empty) list of
323
        watches created.
324
        """
325
326
    def fromMessage(message, bug):
327
        """Create one or more BugWatch's by analysing the given email. The
328
        owner of the BugWatch's will be the sender of the message.
329
        It returns a (possibly empty) list of watches created.
330
        """
331
2487 by Canonical.com Patch Queue Manager
[r=BjornT] Malone URL changes. Yep. Also: contextualize the bug page,
332
    def createBugWatch(bug, owner, bugtracker, remotebug):
333
        """Create an IBugWatch.
334
335
        :bug: The IBug to which the watch is linked.
336
        :owner: The IPerson who created the IBugWatch.
337
        :bugtracker: The external IBugTracker.
338
        :remotebug: A string.
339
        """
3691.174.2 by Bjorn Tillenius
add IBugWatchSet.getBugTrackerAndBug.
340
3691.174.9 by Bjorn Tillenius
getBugTrackerAndBug -> extractBugTrackerAndBug
341
    def extractBugTrackerAndBug(url):
3691.174.2 by Bjorn Tillenius
add IBugWatchSet.getBugTrackerAndBug.
342
        """Extract the bug tracker and the bug number for the given URL.
343
3691.174.9 by Bjorn Tillenius
getBugTrackerAndBug -> extractBugTrackerAndBug
344
        A tuple in the form of (bugtracker, remotebug) is returned,
345
        where bugtracker is a registered IBugTracer, and remotebug is a
346
        text string.
3691.174.2 by Bjorn Tillenius
add IBugWatchSet.getBugTrackerAndBug.
347
348
        A NoBugTrackerFound exception is raised if the base URL can be
349
        extracted, but no such bug tracker is registered in Launchpad.
350
3691.174.9 by Bjorn Tillenius
getBugTrackerAndBug -> extractBugTrackerAndBug
351
        If no bug tracker type can be guessed, None is returned.
3691.174.2 by Bjorn Tillenius
add IBugWatchSet.getBugTrackerAndBug.
352
        """
353
13760.1.1 by Jeroen Vermeulen
Fixing up a few broken utilities, and lint.
354
    def getBugWatchesForRemoteBug(remote_bug, bug_watch_ids=None):
10054.22.7 by Gavin Panella
New method IBugWatchSet.getBugWatchesForRemoteBug().
355
        """Returns bug watches referring to the given remote bug.
356
357
        Returns a set of those bug watches, optionally limited to
358
        those with IDs in `bug_watch_ids`, that refer to `remote_bug`.
359
360
        :param remote_bug_id: The ID of the remote bug.
361
        :type remote_bug_id: See `IBugWatch.remotebug`.
362
363
        :param bug_watch_ids: A collection of `BugWatch` IDs.
364
        :type bug_watch_ids: An iterable of `int`s, or `None`.
365
        """
366
10783.3.8 by Gavin Panella
Rename bulkSetStatus() to bulkSetError().
367
    # XXX: GavinPanella bug=570277 2010-04-26: In bulkSetError() the
368
    # last_error_type argument accepts the same values as the result
369
    # argument to bulkAddActivity(). Using different terms for
370
    # essentially the same thing is confusing.
371
10783.3.11 by Gavin Panella
Make bulkSetError() and bulkAddActivity() ignore arguments that don't look like real bug watches (test doubles, for example).
372
    def bulkSetError(references, last_error_type=None):
10783.3.1 by Gavin Panella
Interfaces for bulk updating of bug watches.
373
        """Efficiently update the status of the given bug watches.
374
375
        Sets the `last_error_type` field as instructed, updates
376
        `lastchecked` to now and resets `next_check` to None, all in
377
        the most efficient way possible.
378
10783.3.11 by Gavin Panella
Make bulkSetError() and bulkAddActivity() ignore arguments that don't look like real bug watches (test doubles, for example).
379
        :param references: An iterable of `IBugWatch` objects or
10783.3.1 by Gavin Panella
Interfaces for bulk updating of bug watches.
380
            primary keys for the same.
381
        :param last_error_type: A member of `BugWatchActivityStatus`
382
            or None.
383
        """
384
7675.655.1 by Tim Penhey
Merge stable, resolve conflicts, disable buildd-slavescanner as I can't understand it.
385
    def bulkAddActivity(references,
7675.648.1 by Michael Hudson
fix the tests
386
                        result=BugWatchActivityStatus.SYNC_SUCCEEDED,
387
                        message=None, oops_id=None):
10783.3.1 by Gavin Panella
Interfaces for bulk updating of bug watches.
388
        """Efficiently add activity for the given bug watches.
389
390
        Add `BugWatchActivity` records for the given bug watches in
391
        the most efficient way possible.
392
10783.3.11 by Gavin Panella
Make bulkSetError() and bulkAddActivity() ignore arguments that don't look like real bug watches (test doubles, for example).
393
        :param references: An iterable of `IBugWatch` objects or
10783.3.1 by Gavin Panella
Interfaces for bulk updating of bug watches.
394
            primary keys for the same.
10783.3.7 by Gavin Panella
In BugWatchActivity, the column is 'result', not 'error'.
395
        :param result: See `IBugWatch.addActivity`.
10783.3.1 by Gavin Panella
Interfaces for bulk updating of bug watches.
396
        :param message: See `IBugWatch.addActivity`.
397
        :param oops_id: See `IBugWatch.addActivity`.
398
        """
399
3691.174.2 by Bjorn Tillenius
add IBugWatchSet.getBugTrackerAndBug.
400
401
class NoBugTrackerFound(Exception):
402
    """No bug tracker with the base_url is registered in Launchpad."""
403
404
    def __init__(self, base_url, remote_bug, bugtracker_type):
405
        Exception.__init__(self, base_url, remote_bug, bugtracker_type)
406
        self.base_url = base_url
407
        self.remote_bug = remote_bug
408
        self.bugtracker_type = bugtracker_type
3691.174.22 by Bjorn Tillenius
review comments.
409
410
411
class UnrecognizedBugTrackerURL(Exception):
412
    """The given URL isn't used by any bug tracker we support."""
7675.586.6 by Graham Binns
Added IBugWatchActivity interface.
413
414
415
class IBugWatchActivity(Interface):
416
    """A record of a single BugWatch update."""
7675.586.7 by Graham Binns
Added BugWatchActivity interfaces.
417
418
    id = Int(
419
        title=_('DB ID'), required=True, readonly=True,
420
        description=_("The unique id of this activity record."))
421
    bug_watch = Reference(
422
        title=_('Bug watch'), required=True, readonly=True, schema=IBugWatch,
423
        description=_(
424
            "The BugWatch whose activity is recorded in this record"))
425
    activity_date = Datetime(
426
        title=_('Activity date'), required=True, readonly=True,
427
        description=_("The date on which this activity occurred."))
428
    result = Choice(
7675.589.1 by Graham Binns
Renamed BugWatchErrorType to BugWatchActivityStatus.
429
        title=_('Result'), vocabulary=BugWatchActivityStatus, readonly=True,
7675.586.7 by Graham Binns
Added BugWatchActivity interfaces.
430
        description=_("The result of the activity."))
431
    message = Text(
432
        title=_('Message'), readonly=True,
433
        description=_("The message associated with this activity."))
434
    oops_id = Text(
435
        title=_('OOPS ID'), readonly=True,
436
        description=_("The OOPS ID associated with this activity."))
437
7675.640.4 by Graham Binns
Added IBugWatch.setNextCheck().
438
439
class BugWatchCannotBeRescheduled(Exception):
440
    """The current `IBugWatch` can't be rescheduled."""