obs: Implement get_srs function
authorEd Bartosh <eduard.bartosh@intel.com>
Sun, 11 May 2014 20:29:50 +0000 (23:29 +0300)
committerEd Bartosh <eduard.bartosh@intel.com>
Mon, 19 May 2014 08:14:46 +0000 (11:14 +0300)
Implemented get_srs to get SRs from the project.
Optionally SRs can be filtered by package and comma-separated
list of statuses.

Change-Id: If003f25e1d54742e13cd1c1d1418598ee4baea15
Signed-off-by: Ed Bartosh <eduard.bartosh@intel.com>
repa/obs.py

index be052e7743a369d7be58a027e5e6214c271adfad..1dd88708e18914b70fff511f4042410bdfb7e7ef 100644 (file)
@@ -181,3 +181,27 @@ class OBS(OSC):
         """Set SR state."""
         return core.change_request_state(self.apiurl, reqid, state,
                                          message=message, force=force)
+
+    def get_srs(self, prj, states=None, pkg=None):
+        """
+        Get SRs for the project (and package).
+
+        Args:
+            prj (str): OBS project name
+            states (str): comma-separated list of states, e.g. 'new,accepted'
+            pkg (str): package name
+
+        Yields:
+            id, state, description of found SRs
+        """
+        query = 'view=collection&types=submit&project=%s' % prj
+        if states:
+            query += '&states=%s' % states
+        if pkg:
+            query += '&package=%s' % pkg
+        url = core.makeurl(self.apiurl, ['request'], query)
+
+        root = ET.parse(self.core_http(core.http_GET, url))
+        for sr in root.findall('request'):
+            yield sr.get('id'), sr.find('state').get('name'), \
+                  sr.find('description').text