OBS: Added new APIs
authorEd Bartosh <eduard.bartosh@intel.com>
Wed, 14 Aug 2013 15:40:07 +0000 (18:40 +0300)
committerEduard Bartosh <eduard.bartosh@intel.com>
Thu, 15 Aug 2013 12:14:58 +0000 (05:14 -0700)
get_source_packages, get_binary_packages and aggregate_packages APIs
have been added to OBS class.

All of added APIs are generic enough to go to oscapi.

All of them are going to be used by repa group subcommand.

Change-Id: I65597edfcad74687a45e9b22d81666f421354e47
Signed-off-by: Ed Bartosh <eduard.bartosh@intel.com>
Reviewed-on: https://otctools.jf.intel.com/review/5899
Tested-by: OTC Tools Tester <ed.bartosh@linux.intel.com>
repa/obs.py

index d672f86..e0d1ef0 100644 (file)
@@ -5,7 +5,7 @@ Copyright (C) Intel Corporation 2013
 Licence: GPL version 2
 Author: Ed Bartosh <eduard.bartosh@intel.com>
 
-OBS module. 
+OBS module.
 Interface module to access Open Build System.
 
 This module is a intermediate step for new APIs
@@ -13,10 +13,12 @@ to oscapi. As soon as APIs are mature enough they
 should be contributed to oscapi.
 """
 
+import sys
 import re
 
 from base64 import b64encode
 from xml.etree import cElementTree as ET
+from StringIO import StringIO
 
 from osc import core
 
@@ -80,6 +82,31 @@ class OBS(OSC):
                 if node.get('code') != 'excluded':
                     pkgresults.append((node.get('package'), code))
             buildres[key]['packages'] = pkgresults
-            
+
         return buildres
 
+
+    def get_source_packages(self, prj):
+        """Get list of binary packages in the project."""
+        return iter(core.meta_get_packagelist(self.apiurl, prj))
+
+
+    def get_binary_packages(self, prj):
+        """Get list of binary packages in the project."""
+        for repo in core.get_repos_of_project(self.apiurl, prj):
+            yield (repo.name, repo.arch), core.get_binarylist(self.apiurl,
+                                                              prj,
+                                                              repo.name,
+                                                              repo.arch)
+
+    @staticmethod
+    def aggregate_package(src_project, src_package, dst_project,
+                          dst_package):
+        """Aggregate package. Wraps core.aggregate_pack."""
+        saved = sys.stdout
+        sys.stdout = StringIO()
+        try:
+            core.aggregate_pac(src_project, src_package,
+                               dst_project, dst_package)
+        finally:
+            sys.stdout = saved