~launchpad-pqm/launchpad/devel

8687.15.17 by Karl Fogel
Add the copyright header block to the rest of the files under lib/lp/.
1
# Copyright 2009 Canonical Ltd.  This software is licensed under the
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
4930.1.1 by David Allouche
Basic CodeImportEvent database classes, interfaces, with implementation and test of CodeImportSet.newCreate.
5
6
"""Code import audit trail interfaces."""
7
8
__metaclass__ = type
9
__all__ = [
10
    'ICodeImportEvent',
11
    'ICodeImportEventSet',
4930.1.7 by David Allouche
CodeImportSet.newModify implementation and tests.
12
    'ICodeImportEventToken',
4930.1.1 by David Allouche
Basic CodeImportEvent database classes, interfaces, with implementation and test of CodeImportSet.newCreate.
13
    ]
14
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
15
from zope.interface import (
16
    Attribute,
17
    Interface,
18
    )
19
from zope.schema import (
20
    Choice,
21
    Datetime,
22
    Int,
23
    )
4930.1.1 by David Allouche
Basic CodeImportEvent database classes, interfaces, with implementation and test of CodeImportSet.newCreate.
24
25
from canonical.launchpad import _
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
26
from lp.code.enums import CodeImportEventType
11318.5.1 by j.c.sackett
Migrated canonical.launchpad.fields to lp.services.fields
27
from lp.services.fields import PublicPersonChoice
6643.2.3 by Michael Hudson
newReclaim
28
4930.1.1 by David Allouche
Basic CodeImportEvent database classes, interfaces, with implementation and test of CodeImportSet.newCreate.
29
30
class ICodeImportEvent(Interface):
31
    """One event in the code-import audit trail."""
32
33
    id = Int(readonly=True, required=True)
34
    date_created = Datetime(
35
        title=_("Date Created"), required=True, readonly=True)
36
37
    event_type = Choice(
38
        title=_("Event"), required=True, readonly=True,
39
        vocabulary=CodeImportEventType,
40
        description=_("The type of this event."""))
41
    code_import = Choice(
42
        title=_("Code Import"), required=False, readonly=True,
43
        vocabulary='CodeImport',
44
        description=_("The code import affected by this event."""))
5485.1.11 by Edwin Grubbs
Using PublicPersonChoice almost everywhere.
45
    person = PublicPersonChoice(
4930.1.1 by David Allouche
Basic CodeImportEvent database classes, interfaces, with implementation and test of CodeImportSet.newCreate.
46
        title=_("Person"), required=False, readonly=True,
47
        vocabulary='Person',
48
        description=_("The person that triggered this event."""))
49
    machine = Choice(
50
        title=_("Machine"), required=False, readonly=True,
51
        vocabulary='CodeImportMachine',
52
        description=_("The import machine where this event occured."""))
53
54
    def items():
55
        """List of key-value tuples recording additional information.
56
57
        Keys are values from the CodeImportEventDataType enum, values are
58
        strings or None.
59
        """
60
61
class ICodeImportEventSet(Interface):
62
    """The set of all CodeImportEvent objects."""
63
64
    def getAll():
65
        """Iterate over all `CodeImportEvent` objects.
66
67
        For use only in tests.
68
        """
69
4930.1.2 by David Allouche
Create CREATE CodeImportEvent from CodeImportSet.new (and newWithId).
70
    def getEventsForCodeImport(code_import):
71
        """Iterate over `CodeImportEvent` objects associated to a CodeImport.
72
        """
73
4930.1.1 by David Allouche
Basic CodeImportEvent database classes, interfaces, with implementation and test of CodeImportSet.newCreate.
74
    def newCreate(code_import, person):
75
        """Record the creation of a `CodeImport` object.
76
77
        Should only be called by CodeImportSet.new.
78
79
        :param code_import: Newly created `CodeImport` object.
80
        :param user: User that created the object, usually the view's user.
81
        :return: `CodeImportEvent` with type CREATE.
82
        """
4930.1.7 by David Allouche
CodeImportSet.newModify implementation and tests.
83
84
    def beginModify(code_import):
85
        """Create the token to give to `newModify`.
86
4930.1.15 by David Allouche
Fixes from mwhudson's review.
87
        Should only be called by `CodeImport` methods.
88
89
        The token records the state of the code import before modification, it
90
        lets newModify find what changes were done.
4930.1.7 by David Allouche
CodeImportSet.newModify implementation and tests.
91
92
        :param code_import: `CodeImport` that will be modified.
4930.1.10 by David Allouche
Self-review fixes.
93
        :return: `CodeImportEventToken` to pass to `newModify`.
4930.1.7 by David Allouche
CodeImportSet.newModify implementation and tests.
94
        """
95
96
    def newModify(code_import, person, token):
97
        """Record a modification to a `CodeImport` object.
98
4930.1.15 by David Allouche
Fixes from mwhudson's review.
99
        Should only be called by `CodeImport` methods.
4930.1.7 by David Allouche
CodeImportSet.newModify implementation and tests.
100
101
        If no change is found between the code import and the data saved in
4930.1.10 by David Allouche
Self-review fixes.
102
        the token, the modification is considered non-significant and no
103
        event object is created.
4930.1.7 by David Allouche
CodeImportSet.newModify implementation and tests.
104
105
        :param code_import: Modified `CodeImport`.
106
        :param person: `Person` who requested the change.
4930.1.10 by David Allouche
Self-review fixes.
107
        :param token: `CodeImportEventToken` created by `beginModify`.
108
        :return: `CodeImportEvent` of MODIFY type, or None.
4930.1.7 by David Allouche
CodeImportSet.newModify implementation and tests.
109
        """
110
5283.8.7 by David Allouche
CodeImportEventSet.newRequest
111
    def newRequest(code_import, person):
112
        """Record that user requested an immediate run of this import.
113
114
        Only called by `CodeImportJobWorkflow.requestJob`.
115
116
        :param code_import: `CodeImport` for which an immediate run was
117
            requested.
118
        :param person: `Person` who requested the code import to run.
119
        :return: `CodeImportEvent` of REQUEST type.
120
        """
121
6233.5.2 by Tim Penhey
Get the page working.
122
    def newOnline(machine, user=None, message=None):
4930.2.1 by David Allouche
CodeImportEventSet.newOnline().
123
        """Record that an import machine went online.
124
125
        :param machine: `CodeImportMachine` whose state changed to ONLINE.
6233.5.2 by Tim Penhey
Get the page working.
126
        :param user: `Person` that requested going online if done by a user.
127
        :param message: User-provided message.
4930.2.1 by David Allouche
CodeImportEventSet.newOnline().
128
        :return: `CodeImportEvent` of ONLINE type.
129
        """
130
6233.5.2 by Tim Penhey
Get the page working.
131
    def newOffline(machine, reason, user=None, message=None):
4930.2.2 by David Allouche
CodeImportEventSet.newOffline().
132
        """Record that an import machine went offline.
133
134
        :param machine: `CodeImportMachine` whose state changed to OFFLINE.
135
        :param reason: `CodeImportMachineOfflineReason` enum value.
6233.5.2 by Tim Penhey
Get the page working.
136
        :param user: `Person` that requested going offline if done by a user.
137
        :param message: User-provided message.
4930.2.2 by David Allouche
CodeImportEventSet.newOffline().
138
        :return: `CodeImportEvent` of OFFLINE type.
139
        """
140
6233.5.2 by Tim Penhey
Get the page working.
141
    def newQuiesce(machine, user, message=None):
4930.2.7 by David Allouche
Record machine in QUIESCE events.
142
        """Record that user requested the machine to quiesce for maintenance.
4930.2.3 by David Allouche
CodeImportEventSet.newQuiesce().
143
4930.2.11 by David Allouche
Self-review tweaks.
144
        :param machine: `CodeImportMachine` whose state changed to QUIESCING.
4930.2.3 by David Allouche
CodeImportEventSet.newQuiesce().
145
        :param user: `Person` that requested quiescing.
4930.2.11 by David Allouche
Self-review tweaks.
146
        :param message: User-provided message.
4930.2.3 by David Allouche
CodeImportEventSet.newQuiesce().
147
        :return: `CodeImportEvent` of QUIESCE type.
148
        """
149
5646.1.1 by Michael Hudson
newStart and newFinish
150
    def newStart(code_import, machine):
151
        """Record that a machine is about to start working on a code import.
152
153
        :param code_import: The `CodeImport` which is about to be worked on.
154
        :param machine: `CodeImportMachine` which is about to start the job.
155
        :return: `CodeImportEvent` of START type.
156
        """
157
158
    def newFinish(code_import, machine):
159
        """Record that a machine has finished working on a code import.
160
161
        :param code_import: The `CodeImport` which is no longer being worked
162
                            on.
163
        :param machine: `CodeImportMachine` which is no longer working on this
164
                        import.
165
        :return: `CodeImportEvent` of FINISH type.
166
        """
167
6643.2.2 by Michael Hudson
gar, simplify
168
    def newKill(code_import, machine):
6643.2.1 by Michael Hudson
bish bash bosh
169
        """Record that a code import job was killed.
170
171
        :param code_import: The `CodeImport` killed job was working on.
172
        :param machine: `CodeImportMachine` on which the job was running.
173
        :return: `CodeImportEvent` of KILL type.
174
        """
175
6643.2.3 by Michael Hudson
newReclaim
176
    def newReclaim(code_import, machine, job_id):
177
        """Record that a code import job was reclaimed by the watchdog.
178
179
        :param code_import: The `CodeImport` killed job was working on.
180
        :param machine: `CodeImportMachine` on which the job was running.
181
        :param job_id: The database id of the reclaimed job.
182
        :return: `CodeImportEvent` of RECLAIM type.
183
        """
184
4930.1.7 by David Allouche
CodeImportSet.newModify implementation and tests.
185
186
class ICodeImportEventToken(Interface):
187
    """Opaque structure returned by `ICodeImportEventSet.beginModify`."""
188
189
    items = Attribute(_("Private data."))