Merge ~cjwatson/launchpad:export-getSourceFilter into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 712f8e6483fd56c21f06732249c468c3f3b8cdad
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:export-getSourceFilter
Merge into: launchpad:master
Diff against target: 263 lines (+69/-27)
8 files modified
lib/lp/_schema_circular_imports.py (+3/-0)
lib/lp/services/webservice/wadl-to-refhtml.xsl (+9/-0)
lib/lp/soyuz/browser/configure.zcml (+5/-1)
lib/lp/soyuz/browser/distroarchseries.py (+10/-2)
lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py (+14/-11)
lib/lp/soyuz/interfaces/distroarchseries.py (+5/-0)
lib/lp/soyuz/interfaces/distroarchseriesfilter.py (+20/-12)
lib/lp/soyuz/interfaces/webservice.py (+3/-1)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Ioana Lasc (community) Approve
Review via email: mp+373625@code.launchpad.net

Commit message

Export IDistroArchSeries.getSourceFilter

This allows webservice users to find out which source filters are
currently set.

I had to export IDistroArchSeriesFilter to make this work. Since there
can only be one source filter per DAS (enforced by a DB constraint), the
URL is just the DAS URL with +source-filter appended.

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) :
review: Approve
Revision history for this message
Otto Co-Pilot (otto-copilot) wrote :
Revision history for this message
Colin Watson (cjwatson) wrote :

Self-approving to work around incorrect repository reviewer.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/_schema_circular_imports.py b/lib/lp/_schema_circular_imports.py
2index cffb8ab..20db323 100644
3--- a/lib/lp/_schema_circular_imports.py
4+++ b/lib/lp/_schema_circular_imports.py
5@@ -189,6 +189,7 @@ from lp.soyuz.interfaces.binarypackagerelease import (
6 )
7 from lp.soyuz.interfaces.buildrecords import IHasBuildRecords
8 from lp.soyuz.interfaces.distroarchseries import IDistroArchSeries
9+from lp.soyuz.interfaces.distroarchseriesfilter import IDistroArchSeriesFilter
10 from lp.soyuz.interfaces.livefs import ILiveFSView
11 from lp.soyuz.interfaces.livefsbuild import (
12 ILiveFSBuild,
13@@ -496,6 +497,8 @@ patch_reference_property(
14 patch_reference_property(IDistroArchSeries, 'main_archive', IArchive)
15 patch_plain_parameter_type(
16 IDistroArchSeries, 'setChrootFromBuild', 'livefsbuild', ILiveFSBuild)
17+patch_entry_return_type(
18+ IDistroArchSeries, 'getSourceFilter', IDistroArchSeriesFilter)
19 patch_plain_parameter_type(
20 IDistroArchSeries, 'setSourceFilter', 'packageset', IPackageset)
21
22diff --git a/lib/lp/services/webservice/wadl-to-refhtml.xsl b/lib/lp/services/webservice/wadl-to-refhtml.xsl
23index 3df6657..d5198b0 100644
24--- a/lib/lp/services/webservice/wadl-to-refhtml.xsl
25+++ b/lib/lp/services/webservice/wadl-to-refhtml.xsl
26@@ -299,6 +299,15 @@
27 <xsl:text>/</xsl:text>
28 <var>&lt;architecture_tag&gt;</var>
29 </xsl:when>
30+ <xsl:when test="@id = 'distro_arch_series_filter'">
31+ <xsl:text>/</xsl:text>
32+ <var>&lt;distribution.name&gt;</var>
33+ <xsl:text>/</xsl:text>
34+ <var>&lt;distroseries.name&gt;</var>
35+ <xsl:text>/</xsl:text>
36+ <var>&lt;architecture_tag&gt;</var>
37+ <xsl:text>/+source-filter</xsl:text>
38+ </xsl:when>
39 <xsl:when test="@id = 'distro_series'">
40 <xsl:text>/</xsl:text>
41 <var>&lt;distribution.name&gt;</var>
42diff --git a/lib/lp/soyuz/browser/configure.zcml b/lib/lp/soyuz/browser/configure.zcml
43index 595aedf..1ce6b53 100644
44--- a/lib/lp/soyuz/browser/configure.zcml
45+++ b/lib/lp/soyuz/browser/configure.zcml
46@@ -1,4 +1,4 @@
47-<!-- Copyright 2009-2015 Canonical Ltd. This software is licensed under the
48+<!-- Copyright 2009-2019 Canonical Ltd. This software is licensed under the
49 GNU Affero General Public License version 3 (see the file LICENSE).
50 -->
51
52@@ -156,6 +156,10 @@
53 template="../templates/distroarchseriesbinarypackagerelease-portlet-details.pt"/>
54 </browser:pages>
55 <browser:url
56+ for="lp.soyuz.interfaces.distroarchseriesfilter.IDistroArchSeriesFilter"
57+ path_expression="string:+source-filter"
58+ attribute_to_parent="distroarchseries"/>
59+ <browser:url
60 for="lp.soyuz.interfaces.archive.IArchiveSet"
61 path_expression="string:archives"
62 parent_utility="lp.services.webapp.interfaces.ILaunchpadRoot"
63diff --git a/lib/lp/soyuz/browser/distroarchseries.py b/lib/lp/soyuz/browser/distroarchseries.py
64index 24cbc76..949809b 100644
65--- a/lib/lp/soyuz/browser/distroarchseries.py
66+++ b/lib/lp/soyuz/browser/distroarchseries.py
67@@ -1,4 +1,4 @@
68-# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
69+# Copyright 2009-2019 Canonical Ltd. This software is licensed under the
70 # GNU Affero General Public License version 3 (see the file LICENSE).
71
72 __metaclass__ = type
73@@ -33,7 +33,10 @@ from lp.services.webapp.menu import (
74 Link,
75 NavigationMenu,
76 )
77-from lp.services.webapp.publisher import canonical_url
78+from lp.services.webapp.publisher import (
79+ canonical_url,
80+ stepto,
81+ )
82 from lp.soyuz.browser.packagesearch import PackageSearchViewBase
83 from lp.soyuz.interfaces.distroarchseries import IDistroArchSeries
84
85@@ -42,6 +45,11 @@ class DistroArchSeriesNavigation(GetitemNavigation):
86
87 usedfor = IDistroArchSeries
88
89+ @stepto('+source-filter')
90+ def traverse_source_filter(self):
91+ """Traverse to the `IDistroArchSeriesFilter` for this DAS, if any."""
92+ return self.context.getSourceFilter()
93+
94
95 class DistroArchSeriesBreadcrumb(Breadcrumb):
96 """Builds a breadcrumb for `DistroArchSeries`."""
97diff --git a/lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py b/lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py
98index 9a7748f..74290a4 100644
99--- a/lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py
100+++ b/lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py
101@@ -11,7 +11,11 @@ from lazr.restfulclient.errors import (
102 BadRequest,
103 Unauthorized,
104 )
105-from testtools.matchers import MatchesStructure
106+from testtools.matchers import (
107+ EndsWith,
108+ Equals,
109+ MatchesStructure,
110+ )
111 from zope.security.management import endInteraction
112
113 from lp.buildmaster.enums import BuildBaseImageType
114@@ -334,15 +338,14 @@ class TestDistroArchSeriesWebservice(TestCaseWithFactory):
115 webservice = launchpadlib_for("testing", user, version="devel")
116 ws_das = ws_object(webservice, das)
117 ws_das.setSourceFilter(packageset=packageset_url, sense="Include")
118- with person_logged_in(user):
119- dasf = das.getSourceFilter()
120- self.assertThat(dasf, MatchesStructure.byEquality(
121- packageset=packageset, sense=DistroArchSeriesFilterSense.INCLUDE))
122+ ws_dasf = ws_das.getSourceFilter()
123+ self.assertThat(ws_dasf, MatchesStructure(
124+ packageset_link=EndsWith(packageset_url),
125+ sense=Equals("Include")))
126 ws_das.setSourceFilter(packageset=packageset_url, sense="Exclude")
127- with person_logged_in(user):
128- dasf = das.getSourceFilter()
129- self.assertThat(dasf, MatchesStructure.byEquality(
130- packageset=packageset, sense=DistroArchSeriesFilterSense.EXCLUDE))
131+ ws_dasf = ws_das.getSourceFilter()
132+ self.assertThat(ws_dasf, MatchesStructure(
133+ packageset_link=EndsWith(packageset_url),
134+ sense=Equals("Exclude")))
135 ws_das.removeSourceFilter()
136- with person_logged_in(user):
137- self.assertIsNone(das.getSourceFilter())
138+ self.assertIsNone(ws_das.getSourceFilter())
139diff --git a/lib/lp/soyuz/interfaces/distroarchseries.py b/lib/lp/soyuz/interfaces/distroarchseries.py
140index 02b4a92..8f5caa1 100644
141--- a/lib/lp/soyuz/interfaces/distroarchseries.py
142+++ b/lib/lp/soyuz/interfaces/distroarchseries.py
143@@ -24,6 +24,7 @@ from lazr.restful.declarations import (
144 exported,
145 operation_for_version,
146 operation_parameters,
147+ operation_returns_entry,
148 REQUEST_USER,
149 )
150 from lazr.restful.fields import (
151@@ -233,6 +234,10 @@ class IDistroArchSeriesPublic(IHasBuildRecords, IHasOwner):
152 this distro arch series.
153 """
154
155+ # Really IDistroArchSeriesFilter, patched in _schema_circular_imports.py.
156+ @operation_returns_entry(Interface)
157+ @export_read_operation()
158+ @operation_for_version("devel")
159 def getSourceFilter():
160 """Get the filter for packages to build for this architecture, if any.
161
162diff --git a/lib/lp/soyuz/interfaces/distroarchseriesfilter.py b/lib/lp/soyuz/interfaces/distroarchseriesfilter.py
163index a78e1fa..1cc324a 100644
164--- a/lib/lp/soyuz/interfaces/distroarchseriesfilter.py
165+++ b/lib/lp/soyuz/interfaces/distroarchseriesfilter.py
166@@ -12,6 +12,10 @@ __all__ = [
167 'NoSuchDistroArchSeriesFilter',
168 ]
169
170+from lazr.restful.declarations import (
171+ export_as_webservice_entry,
172+ exported,
173+ )
174 from lazr.restful.fields import Reference
175 from zope.interface import Interface
176 from zope.schema import (
177@@ -39,37 +43,37 @@ class IDistroArchSeriesFilterView(Interface):
178
179 id = Int(title=_("ID"), readonly=True, required=True)
180
181- distroarchseries = Reference(
182+ distroarchseries = exported(Reference(
183 title=_("Distro arch series"), required=True, readonly=True,
184 schema=IDistroArchSeries,
185- description=_("The distro arch series that this filter is for."))
186+ description=_("The distro arch series that this filter is for.")))
187
188- packageset = Reference(
189+ packageset = exported(Reference(
190 title=_("Package set"), required=True, readonly=True,
191 schema=IPackageset,
192 description=_(
193 "The package set to be included in or excluded from this distro "
194- "arch series."))
195+ "arch series.")))
196
197- sense = Choice(
198+ sense = exported(Choice(
199 title=_("Sense"),
200 vocabulary=DistroArchSeriesFilterSense, required=True, readonly=True,
201 description=_(
202 "Whether the filter represents packages to include or exclude "
203- "from the distro arch series."))
204+ "from the distro arch series.")))
205
206- creator = PublicPersonChoice(
207+ creator = exported(PublicPersonChoice(
208 title=_("Creator"), required=True, readonly=True,
209 vocabulary="ValidPerson",
210- description=_("The user who created this filter."))
211+ description=_("The user who created this filter.")))
212
213- date_created = Datetime(
214+ date_created = exported(Datetime(
215 title=_("Date created"), required=True, readonly=True,
216- description=_("The time when this filter was created."))
217+ description=_("The time when this filter was created.")))
218
219- date_last_modified = Datetime(
220+ date_last_modified = exported(Datetime(
221 title=_("Date last modified"), required=True, readonly=True,
222- description=_("The time when this filter was last modified."))
223+ description=_("The time when this filter was last modified.")))
224
225 def isSourceIncluded(sourcepackagename):
226 """Is this source package name included by this filter?
227@@ -103,6 +107,10 @@ class IDistroArchSeriesFilter(
228 exclude some packages ("this architecture can't handle some packages so
229 we want to make them go away centrally").
230 """
231+ # XXX cjwatson 2019-10-04 bug=760849: "beta" is a lie to get WADL
232+ # generation working. Individual attributes must set their version to
233+ # "devel".
234+ export_as_webservice_entry(as_of="beta")
235
236
237 class IDistroArchSeriesFilterSet(Interface):
238diff --git a/lib/lp/soyuz/interfaces/webservice.py b/lib/lp/soyuz/interfaces/webservice.py
239index 21591de..3620e81 100644
240--- a/lib/lp/soyuz/interfaces/webservice.py
241+++ b/lib/lp/soyuz/interfaces/webservice.py
242@@ -1,4 +1,4 @@
243-# Copyright 2010-2017 Canonical Ltd. This software is licensed under the
244+# Copyright 2010-2019 Canonical Ltd. This software is licensed under the
245 # GNU Affero General Public License version 3 (see the file LICENSE).
246
247 """All the interfaces that are exposed through the webservice.
248@@ -30,6 +30,7 @@ __all__ = [
249 'IBinaryPackagePublishingHistory',
250 'IBinaryPackageReleaseDownloadCount',
251 'IDistroArchSeries',
252+ 'IDistroArchSeriesFilter',
253 'ILiveFS',
254 'ILiveFSBuild',
255 'ILiveFSSet',
256@@ -87,6 +88,7 @@ from lp.soyuz.interfaces.binarypackagerelease import (
257 IBinaryPackageReleaseDownloadCount,
258 )
259 from lp.soyuz.interfaces.distroarchseries import IDistroArchSeries
260+from lp.soyuz.interfaces.distroarchseriesfilter import IDistroArchSeriesFilter
261 from lp.soyuz.interfaces.livefs import (
262 ILiveFS,
263 ILiveFSSet,

Subscribers

People subscribed via source and target branches

to status/vote changes: