Merge lp:~jml/launchpad/get-published-sources-component-name into lp:launchpad

Proposed by Jonathan Lange
Status: Merged
Approved by: Benji York
Approved revision: no longer in the source branch.
Merged at revision: 13929
Proposed branch: lp:~jml/launchpad/get-published-sources-component-name
Merge into: lp:launchpad
Diff against target: 118 lines (+52/-3)
4 files modified
lib/lp/soyuz/interfaces/archive.py (+7/-2)
lib/lp/soyuz/model/archive.py (+7/-1)
lib/lp/soyuz/stories/webservice/xx-archive.txt (+26/-0)
lib/lp/soyuz/tests/test_archive.py (+12/-0)
To merge this branch: bzr merge lp:~jml/launchpad/get-published-sources-component-name
Reviewer Review Type Date Requested Status
Benji York (community) code Approve
Review via email: mp+75054@code.launchpad.net

Commit message

[r=benji][bug=848097] add another filter to IArchive.getPublishedSources; make it possible to filter by component name

Description of the change

This branch adds another filter to IArchive.getPublishedSources. It makes it possible to filter by component name.

This is driven by a need from the Ubuntu team to be able to get a list of packages within a particular component over the API. I wrote the branch up as a favour. It's pretty straightforward.

To post a comment you must log in.
Revision history for this message
Benji York (benji) wrote :

This branch looks good.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/soyuz/interfaces/archive.py'
2--- lib/lp/soyuz/interfaces/archive.py 2011-09-06 10:45:39 +0000
3+++ lib/lp/soyuz/interfaces/archive.py 2011-09-12 18:11:01 +0000
4@@ -949,7 +949,10 @@
5 title=_("Created Since Date"),
6 description=_("Return entries whose `date_created` is greater "
7 "than or equal to this date."),
8- required=False))
9+ required=False),
10+ component_name=TextLine(title=_("Component name"), required=False),
11+ )
12+
13 # Really returns ISourcePackagePublishingHistory, see below for
14 # patch to avoid circular import.
15 @call_with(eager_load=True)
16@@ -958,7 +961,7 @@
17 def getPublishedSources(name=None, version=None, status=None,
18 distroseries=None, pocket=None,
19 exact_match=False, created_since_date=None,
20- eager_load=False):
21+ eager_load=False, component_name=None):
22 """All `ISourcePackagePublishingHistory` target to this archive.
23
24 :param name: source name filter (exact match or SQL LIKE controlled
25@@ -973,6 +976,8 @@
26 matching.
27 :param created_since_date: Only return results whose `date_created`
28 is greater than or equal to this date.
29+ :param component_name: component filter. Only return source packages
30+ that are in this component.
31
32 :return: SelectResults containing `ISourcePackagePublishingHistory`,
33 ordered by name. If there are multiple results for the same
34
35=== modified file 'lib/lp/soyuz/model/archive.py'
36--- lib/lp/soyuz/model/archive.py 2011-09-05 16:40:34 +0000
37+++ lib/lp/soyuz/model/archive.py 2011-09-12 18:11:01 +0000
38@@ -495,7 +495,7 @@
39 def getPublishedSources(self, name=None, version=None, status=None,
40 distroseries=None, pocket=None,
41 exact_match=False, created_since_date=None,
42- eager_load=False):
43+ eager_load=False, component_name=None):
44 """See `IArchive`."""
45 # clauses contains literal sql expressions for things that don't work
46 # easily in storm : this method was migrated from sqlobject but some
47@@ -535,6 +535,12 @@
48 else:
49 orderBy.insert(1, Desc(SourcePackageRelease.version))
50
51+ if component_name is not None:
52+ storm_clauses.extend(
53+ [SourcePackagePublishingHistory.componentID == Component.id,
54+ Component.name == component_name,
55+ ])
56+
57 if status is not None:
58 try:
59 status = tuple(status)
60
61=== modified file 'lib/lp/soyuz/stories/webservice/xx-archive.txt'
62--- lib/lp/soyuz/stories/webservice/xx-archive.txt 2011-08-28 08:36:14 +0000
63+++ lib/lp/soyuz/stories/webservice/xx-archive.txt 2011-09-12 18:11:01 +0000
64@@ -676,6 +676,32 @@
65 >>> print response.getheader('status')
66 400 Bad Request
67
68+We don't have to specify any filters when getting published sources:
69+
70+ >>> response = webservice.named_get(
71+ ... cprov_archive['self_link'], 'getPublishedSources').jsonBody()
72+ >>> print response['total_size']
73+ 3
74+
75+We can filter getPublishedSources() by component. All of the publishing
76+histories we got previously were in 'main':
77+
78+ >>> for entry in response['entries']:
79+ ... print entry['component_name']
80+ main
81+ main
82+ main
83+
84+When we filter by component name for 'universe', none of them show up:
85+
86+ >>> response = webservice.named_get(
87+ ... cprov_archive['self_link'], 'getPublishedSources',
88+ ... component_name='universe').jsonBody()
89+ >>> pprint_entry(response)
90+ entries: []
91+ start: 0
92+ total_size: 0
93+
94
95 Package copying/synchronisation
96 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
97
98=== modified file 'lib/lp/soyuz/tests/test_archive.py'
99--- lib/lp/soyuz/tests/test_archive.py 2011-09-05 16:40:34 +0000
100+++ lib/lp/soyuz/tests/test_archive.py 2011-09-12 18:11:01 +0000
101@@ -2006,6 +2006,18 @@
102 PackagePublishingPocket.UPDATES],
103 [source.pocket for source in filtered])
104
105+ def test_filter_by_component_name(self):
106+ # getPublishedSources() can be filtered by component name.
107+ distroseries = self.factory.makeDistroSeries()
108+ for component in getUtility(IComponentSet):
109+ self.factory.makeSourcePackagePublishingHistory(
110+ distroseries=distroseries,
111+ component=component,
112+ )
113+ [filtered] = distroseries.main_archive.getPublishedSources(
114+ component_name='universe')
115+ self.assertEqual('universe', filtered.component.name)
116+
117
118 class TestSyncSourceFeatureFlag(TestCaseWithFactory):
119