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
=== modified file 'lib/lp/soyuz/interfaces/archive.py'
--- lib/lp/soyuz/interfaces/archive.py 2011-09-06 10:45:39 +0000
+++ lib/lp/soyuz/interfaces/archive.py 2011-09-12 18:11:01 +0000
@@ -949,7 +949,10 @@
949 title=_("Created Since Date"),949 title=_("Created Since Date"),
950 description=_("Return entries whose `date_created` is greater "950 description=_("Return entries whose `date_created` is greater "
951 "than or equal to this date."),951 "than or equal to this date."),
952 required=False))952 required=False),
953 component_name=TextLine(title=_("Component name"), required=False),
954 )
955
953 # Really returns ISourcePackagePublishingHistory, see below for956 # Really returns ISourcePackagePublishingHistory, see below for
954 # patch to avoid circular import.957 # patch to avoid circular import.
955 @call_with(eager_load=True)958 @call_with(eager_load=True)
@@ -958,7 +961,7 @@
958 def getPublishedSources(name=None, version=None, status=None,961 def getPublishedSources(name=None, version=None, status=None,
959 distroseries=None, pocket=None,962 distroseries=None, pocket=None,
960 exact_match=False, created_since_date=None,963 exact_match=False, created_since_date=None,
961 eager_load=False):964 eager_load=False, component_name=None):
962 """All `ISourcePackagePublishingHistory` target to this archive.965 """All `ISourcePackagePublishingHistory` target to this archive.
963966
964 :param name: source name filter (exact match or SQL LIKE controlled967 :param name: source name filter (exact match or SQL LIKE controlled
@@ -973,6 +976,8 @@
973 matching.976 matching.
974 :param created_since_date: Only return results whose `date_created`977 :param created_since_date: Only return results whose `date_created`
975 is greater than or equal to this date.978 is greater than or equal to this date.
979 :param component_name: component filter. Only return source packages
980 that are in this component.
976981
977 :return: SelectResults containing `ISourcePackagePublishingHistory`,982 :return: SelectResults containing `ISourcePackagePublishingHistory`,
978 ordered by name. If there are multiple results for the same983 ordered by name. If there are multiple results for the same
979984
=== modified file 'lib/lp/soyuz/model/archive.py'
--- lib/lp/soyuz/model/archive.py 2011-09-05 16:40:34 +0000
+++ lib/lp/soyuz/model/archive.py 2011-09-12 18:11:01 +0000
@@ -495,7 +495,7 @@
495 def getPublishedSources(self, name=None, version=None, status=None,495 def getPublishedSources(self, name=None, version=None, status=None,
496 distroseries=None, pocket=None,496 distroseries=None, pocket=None,
497 exact_match=False, created_since_date=None,497 exact_match=False, created_since_date=None,
498 eager_load=False):498 eager_load=False, component_name=None):
499 """See `IArchive`."""499 """See `IArchive`."""
500 # clauses contains literal sql expressions for things that don't work500 # clauses contains literal sql expressions for things that don't work
501 # easily in storm : this method was migrated from sqlobject but some501 # easily in storm : this method was migrated from sqlobject but some
@@ -535,6 +535,12 @@
535 else:535 else:
536 orderBy.insert(1, Desc(SourcePackageRelease.version))536 orderBy.insert(1, Desc(SourcePackageRelease.version))
537537
538 if component_name is not None:
539 storm_clauses.extend(
540 [SourcePackagePublishingHistory.componentID == Component.id,
541 Component.name == component_name,
542 ])
543
538 if status is not None:544 if status is not None:
539 try:545 try:
540 status = tuple(status)546 status = tuple(status)
541547
=== modified file 'lib/lp/soyuz/stories/webservice/xx-archive.txt'
--- lib/lp/soyuz/stories/webservice/xx-archive.txt 2011-08-28 08:36:14 +0000
+++ lib/lp/soyuz/stories/webservice/xx-archive.txt 2011-09-12 18:11:01 +0000
@@ -676,6 +676,32 @@
676 >>> print response.getheader('status')676 >>> print response.getheader('status')
677 400 Bad Request677 400 Bad Request
678678
679We don't have to specify any filters when getting published sources:
680
681 >>> response = webservice.named_get(
682 ... cprov_archive['self_link'], 'getPublishedSources').jsonBody()
683 >>> print response['total_size']
684 3
685
686We can filter getPublishedSources() by component. All of the publishing
687histories we got previously were in 'main':
688
689 >>> for entry in response['entries']:
690 ... print entry['component_name']
691 main
692 main
693 main
694
695When we filter by component name for 'universe', none of them show up:
696
697 >>> response = webservice.named_get(
698 ... cprov_archive['self_link'], 'getPublishedSources',
699 ... component_name='universe').jsonBody()
700 >>> pprint_entry(response)
701 entries: []
702 start: 0
703 total_size: 0
704
679705
680Package copying/synchronisation706Package copying/synchronisation
681~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~707~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
682708
=== modified file 'lib/lp/soyuz/tests/test_archive.py'
--- lib/lp/soyuz/tests/test_archive.py 2011-09-05 16:40:34 +0000
+++ lib/lp/soyuz/tests/test_archive.py 2011-09-12 18:11:01 +0000
@@ -2006,6 +2006,18 @@
2006 PackagePublishingPocket.UPDATES],2006 PackagePublishingPocket.UPDATES],
2007 [source.pocket for source in filtered])2007 [source.pocket for source in filtered])
20082008
2009 def test_filter_by_component_name(self):
2010 # getPublishedSources() can be filtered by component name.
2011 distroseries = self.factory.makeDistroSeries()
2012 for component in getUtility(IComponentSet):
2013 self.factory.makeSourcePackagePublishingHistory(
2014 distroseries=distroseries,
2015 component=component,
2016 )
2017 [filtered] = distroseries.main_archive.getPublishedSources(
2018 component_name='universe')
2019 self.assertEqual('universe', filtered.component.name)
2020
20092021
2010class TestSyncSourceFeatureFlag(TestCaseWithFactory):2022class TestSyncSourceFeatureFlag(TestCaseWithFactory):
20112023