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
|
# 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',
'recipes_enabled',
]
from textwrap import dedent
from lazr.restful.declarations import (
call_with,
export_as_webservice_entry,
export_write_operation,
exported,
operation_parameters,
REQUEST_USER,
)
from lazr.restful.fields import (
CollectionField,
Reference,
)
from zope.interface import (
Attribute,
Interface,
)
from zope.schema import (
Bool,
Choice,
Datetime,
Int,
Object,
Text,
TextLine,
)
from canonical.config import config
from canonical.launchpad import _
from canonical.launchpad.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 import features
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 = Object(
schema=IBranch, title=_("Base branch"), description=_(
"The base branch to use when building the recipe."))
deb_version_template = TextLine(
title=_('deb-version template'),
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())
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.
"""
def getBuilds():
"""Return a ResultSet of all the non-pending builds."""
def getPendingBuilds():
"""Return a ResultSet of all the pending builds."""
def getLastBuild():
"""Return the the most recent build of this recipe."""
@call_with(requester=REQUEST_USER)
@operation_parameters(
archive=Reference(schema=IArchive),
distroseries=Reference(schema=IDistroSeries),
pocket=Choice(vocabulary=PackagePublishingPocket,))
@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.
"""
class ISourcePackageRecipeEdit(Interface):
"""ISourcePackageRecipe methods that require launchpad.Edit permission."""
@operation_parameters(recipe_text=Text())
@export_write_operation()
def setRecipeText(recipe_text):
"""Set the text of the recipe."""
def destroySelf():
"""Remove this SourcePackageRecipe from the database.
This requires deleting any rows with non-nullable foreign key
references to this object.
"""
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 = CollectionField(
Reference(IDistroSeries), title=_("The distroseries this recipe will"
" build a source package for"),
readonly=False)
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 this recipe.")))
description = Description(
title=_('Description'), required=True,
description=_('A short description of the recipe.'))
date_last_modified = Datetime(required=True, readonly=True)
is_stale = Bool(title=_('Recipe is stale.'))
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()
base_branch = Reference(
IBranch, title=_("The base branch used by this recipe."),
required=True, readonly=True)
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):
"""Create an `ISourcePackageRecipe`."""
def exists(owner, name):
"""Check to see if a recipe by the same name and owner exists."""
def recipes_enabled():
"""Return True if recipes are enabled."""
# Features win:
if features.getFeatureFlag(u'code.recipes_enabled'):
return True
if not config.build_from_branch.enabled:
return False
return True
|