← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Jonathan Lange has proposed merging lp:~jml/launchpad/get-published-sources-component-name into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #848097 in Launchpad itself: "Not possible to get a list of packages in a component through the API"
  https://bugs.launchpad.net/launchpad/+bug/848097

For more details, see:
https://code.launchpad.net/~jml/launchpad/get-published-sources-component-name/+merge/75054

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.
-- 
https://code.launchpad.net/~jml/launchpad/get-published-sources-component-name/+merge/75054
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jml/launchpad/get-published-sources-component-name into lp:launchpad.
=== 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:09:21 +0000
@@ -949,7 +949,10 @@
             title=_("Created Since Date"),
             description=_("Return entries whose `date_created` is greater "
                           "than or equal to this date."),
-            required=False))
+            required=False),
+        component_name=TextLine(title=_("Component name"), required=False),
+        )
+
     # Really returns ISourcePackagePublishingHistory, see below for
     # patch to avoid circular import.
     @call_with(eager_load=True)
@@ -958,7 +961,7 @@
     def getPublishedSources(name=None, version=None, status=None,
                             distroseries=None, pocket=None,
                             exact_match=False, created_since_date=None,
-                            eager_load=False):
+                            eager_load=False, component_name=None):
         """All `ISourcePackagePublishingHistory` target to this archive.
 
         :param name: source name filter (exact match or SQL LIKE controlled
@@ -973,6 +976,8 @@
                              matching.
         :param created_since_date: Only return results whose `date_created`
             is greater than or equal to this date.
+        :param component_name: component filter. Only return source packages
+            that are in this component.
 
         :return: SelectResults containing `ISourcePackagePublishingHistory`,
             ordered by name. If there are multiple results for the same

=== 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:09:21 +0000
@@ -495,7 +495,7 @@
     def getPublishedSources(self, name=None, version=None, status=None,
                             distroseries=None, pocket=None,
                             exact_match=False, created_since_date=None,
-                            eager_load=False):
+                            eager_load=False, component_name=None):
         """See `IArchive`."""
         # clauses contains literal sql expressions for things that don't work
         # easily in storm : this method was migrated from sqlobject but some
@@ -535,6 +535,12 @@
         else:
             orderBy.insert(1, Desc(SourcePackageRelease.version))
 
+        if component_name is not None:
+            storm_clauses.extend(
+                [SourcePackagePublishingHistory.componentID == Component.id,
+                 Component.name == component_name,
+                 ])
+
         if status is not None:
             try:
                 status = tuple(status)

=== 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:09:21 +0000
@@ -676,6 +676,32 @@
     >>> print response.getheader('status')
     400 Bad Request
 
+We don't have to specify any filters when getting published sources:
+
+    >>> response = webservice.named_get(
+    ...     cprov_archive['self_link'], 'getPublishedSources').jsonBody()
+    >>> print response['total_size']
+    3
+
+We can filter getPublishedSources() by component. All of the publishing
+histories we got previously were in 'main':
+
+    >>> for entry in response['entries']:
+    ...     print entry['component_name']
+    main
+    main
+    main
+
+When we filter by component name for 'universe', none of them show up:
+
+    >>> response = webservice.named_get(
+    ...     cprov_archive['self_link'], 'getPublishedSources',
+    ...     component_name='universe').jsonBody()
+    >>> pprint_entry(response)
+    entries: []
+    start: 0
+    total_size: 0
+
 
 Package copying/synchronisation
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

=== 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:09:21 +0000
@@ -2006,6 +2006,18 @@
              PackagePublishingPocket.UPDATES],
             [source.pocket for source in filtered])
 
+    def test_filter_by_component_name(self):
+        # getPublishedSources() can be filtered by component name.
+        distroseries = self.factory.makeDistroSeries()
+        for component in getUtility(IComponentSet):
+            self.factory.makeSourcePackagePublishingHistory(
+                distroseries=distroseries,
+                component=component,
+                )
+        [filtered] = distroseries.main_archive.getPublishedSources(
+            component_name='universe')
+        self.assertEqual('universe', filtered.component.name)
+
 
 class TestSyncSourceFeatureFlag(TestCaseWithFactory):