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
|
# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
# pylint: disable-msg=E0211,E0213,F0401
"""Interface of the `SourcePackageRecipe` content type."""
__metaclass__ = type
__all__ = [
'ISourcePackageRecipe',
'ISourcePackageRecipeData',
'ISourcePackageRecipeSource',
'MINIMAL_RECIPE_TEXT',
]
from textwrap import dedent
from lazr.restful.declarations import (
call_with,
export_as_webservice_entry,
export_read_operation,
export_write_operation,
exported,
mutator_for,
operation_for_version,
operation_parameters,
operation_returns_entry,
REQUEST_USER,
)
from lazr.restful.fields import (
CollectionField,
Reference,
ReferenceChoice,
)
from lazr.restful.interface import copy_field
from zope.interface import (
Attribute,
Interface,
)
from zope.schema import (
Bool,
Choice,
Datetime,
Int,
List,
Text,
TextLine,
)
from canonical.launchpad import _
from lp.app.validators.name import name_validator
from lp.code.interfaces.branch import IBranch
from lp.registry.interfaces.distroseries import IDistroSeries
from lp.registry.interfaces.pocket import PackagePublishingPocket
from lp.registry.interfaces.role import IHasOwner
from lp.services.fields import (
Description,
PersonChoice,
PublicPersonChoice,
)
from lp.soyuz.interfaces.archive import IArchive
MINIMAL_RECIPE_TEXT = dedent(u'''\
# bzr-builder format 0.3 deb-version {debupstream}-0~{revno}
%s
''')
class ISourcePackageRecipeData(Interface):
"""A recipe as database data, not text."""
base_branch = exported(
Reference(
IBranch, title=_("The base branch used by this recipe."),
required=True, readonly=True))
deb_version_template = exported(
TextLine(
title=_('deb-version template'), readonly=True,
description = _(
'The template that will be used to generate a deb version.')))
def getReferencedBranches():
"""An iterator of the branches referenced by this recipe."""
class ISourcePackageRecipeView(Interface):
"""IBranch attributes that require launchpad.View permission."""
id = Int()
date_created = Datetime(required=True, readonly=True)
registrant = exported(
PublicPersonChoice(
title=_("The person who created this recipe."),
required=True, readonly=True,
vocabulary='ValidPersonOrTeam'))
recipe_text = exported(Text(readonly=True))
pending_builds = exported(
CollectionField(
title=_("The pending builds of this recipe."),
description=_('Pending builds of this recipe, sorted in '
'descending order of creation.'),
value_type=Reference(schema=Interface),
readonly=True))
completed_builds = exported(
CollectionField(
title=_("The completed builds of this recipe."),
description=_('Completed builds of this recipe, sorted in '
'descending order of finishing (or starting if not'
'completed successfully).'),
value_type=Reference(schema=Interface),
readonly=True))
builds = exported(
CollectionField(
title=_("All builds of this recipe."),
description=_('All builds of this recipe, sorted in '
'descending order of finishing (or starting if not'
'completed successfully).'),
value_type=Reference(schema=Interface),
readonly=True))
last_build = exported(
Reference(
Interface,
title=_("The the most recent build of this recipe."),
readonly=True))
def isOverQuota(requester, distroseries):
"""True if the recipe/requester/distroseries combo is >= quota.
:param requester: The Person requesting a build.
:param distroseries: The distroseries to build for.
"""
@call_with(requester=REQUEST_USER)
@operation_parameters(
archive=Reference(schema=IArchive),
distroseries=Reference(schema=IDistroSeries),
pocket=Choice(vocabulary=PackagePublishingPocket,))
@operation_returns_entry(Interface)
@export_write_operation()
def requestBuild(archive, distroseries, requester, pocket):
"""Request that the recipe be built in to the specified archive.
:param archive: The IArchive which you want the build to end up in.
:param requester: the person requesting the build.
:param pocket: the pocket that should be targeted.
:raises: various specific upload errors if the requestor is not
able to upload to the archive.
"""
@export_write_operation()
def performDailyBuild():
"""Perform a build into the daily build archive."""
@export_read_operation()
@operation_for_version("devel")
def getPendingBuildInfo():
"""Find distroseries and archive data for pending builds.
Return a list of dict(
distroseries:distroseries.displayname
archive:archive.token)
The archive token is the same as that defined by the archive vocab:
archive.owner.name/archive.name
This information is used to construct the request builds popup form.
"""
class ISourcePackageRecipeEditableAttributes(IHasOwner):
"""ISourcePackageRecipe attributes that can be edited.
These attributes need launchpad.View to see, and launchpad.Edit to change.
"""
daily_build_archive = exported(Reference(
IArchive, title=_("The archive to use for daily builds.")))
builder_recipe = Attribute(
_("The bzr-builder data structure for the recipe."))
owner = exported(
PersonChoice(
title=_('Owner'),
required=True, readonly=False,
vocabulary='UserTeamsParticipationPlusSelf',
description=_("The person or team who can edit this recipe.")))
distroseries = exported(List(
ReferenceChoice(schema=IDistroSeries,
vocabulary='BuildableDistroSeries'),
title=_("Default distribution series"),
description=_("If built daily, these are the distribution "
"versions that the recipe will be built for."),
readonly=True))
build_daily = exported(Bool(
title=_("Built daily"),
description=_(
"Automatically build each day, if the source has changed.")))
name = exported(TextLine(
title=_("Name"), required=True,
constraint=name_validator,
description=_(
"The name of the recipe is part of the URL and needs to "
"be unique for the given owner.")))
description = exported(Description(
title=_('Description'), required=False,
description=_('A short description of the recipe.')))
date_last_modified = exported(
Datetime(required=True, readonly=True))
is_stale = Bool(title=_('Recipe is stale.'))
class ISourcePackageRecipeEdit(Interface):
"""ISourcePackageRecipe methods that require launchpad.Edit permission."""
@mutator_for(ISourcePackageRecipeView['recipe_text'])
@operation_for_version("devel")
@operation_parameters(
recipe_text=copy_field(
ISourcePackageRecipeView['recipe_text']))
@export_write_operation()
def setRecipeText(recipe_text):
"""Set the text of the recipe."""
@mutator_for(ISourcePackageRecipeEditableAttributes['distroseries'])
@operation_parameters(distroseries=copy_field(
ISourcePackageRecipeEditableAttributes['distroseries']))
@export_write_operation()
@operation_for_version("devel")
def updateSeries(distroseries):
"""Replace this recipe's distro series."""
def destroySelf():
"""Remove this SourcePackageRecipe from the database.
This requires deleting any rows with non-nullable foreign key
references to this object.
"""
class ISourcePackageRecipe(ISourcePackageRecipeData,
ISourcePackageRecipeEdit, ISourcePackageRecipeEditableAttributes,
ISourcePackageRecipeView):
"""An ISourcePackageRecipe describes how to build a source package.
More precisely, it describes how to combine a number of branches into a
debianized source tree.
"""
export_as_webservice_entry()
class ISourcePackageRecipeSource(Interface):
"""A utility of this interface can be used to create and access recipes.
"""
def new(registrant, owner, distroseries, name,
builder_recipe, description, date_created):
"""Create an `ISourcePackageRecipe`."""
def exists(owner, name):
"""Check to see if a recipe by the same name and owner exists."""
|