--- /dev/null
+"""
+REPA: Release Engineering Process Assistant.
+
+Copyright (C) Intel Corporation 2013
+Licence: GPL version 2
+Author: Ed Bartosh <eduard.bartosh@intel.com>
+
+OBS module.
+Interface module to access Open Build System.
+
+This module is a intermediate step for new APIs
+to oscapi. As soon as APIs are mature enough they
+should be contributed to oscapi.
+"""
+
+import re
+
+from base64 import b64encode
+from xml.etree import cElementTree as ET
+
+from osc import core
+
+from gitbuildsys.oscapi import OSC
+from gitbuildsys.utils import Temp
+
+
+OBS_PREFIX = "home:prerelease:"
+
+OSCRC_TEMPLATE = """[general]
+apiurl = %(apiurl)s
+plaintext_passwd=0
+use_keyring=0
+http_debug = %(http_debug)s
+debug = %(debug)s
+gnome_keyring=0
+[%(apiurl)s]
+user=%(user)s
+passx=%(passwdx)s
+"""
+
+class OBS(OSC):
+ """Interface to OBS API."""
+
+ def __init__(self, apiurl, apiuser, apipasswd):
+ oscrc = OSCRC_TEMPLATE % {
+ 'http_debug': 0,
+ "debug": 0,
+ "apiurl": apiurl,
+ "user": apiuser,
+ "passwdx": b64encode(apipasswd.encode('bz2'))}
+
+ self.apiurl = apiurl
+ tmpf = Temp(prefix='.oscrc', content=oscrc)
+ self.oscrcpath = tmpf.path
+ OSC.__init__(self, apiurl, self.oscrcpath)
+
+
+ def get_projects(self, regexp=''):
+ """List projects with attributes."""
+ for project in core.meta_get_project_list(self.apiurl):
+ if regexp and not re.match(regexp, project):
+ continue
+ yield project, self.get_description(project)
+
+
+ def get_build_results(self, prj):
+ """Get project build results."""
+ meta = core.show_prj_results_meta(self.apiurl, prj)
+ root = ET.fromstring(''.join(meta))
+ buildres = {}
+ if not root.find('result'):
+ return buildres
+ for results in root.findall('result'):
+ key = (results.get('repository'), results.get('arch'))
+ buildres[key] = dict([(field, results.get(field)) \
+ for field in ('code', 'state')])
+ pkgresults = []
+ for node in results:
+ code = node.get('code')
+ if node.get('code') != 'excluded':
+ pkgresults.append((node.get('package'), code))
+ buildres[key]['packages'] = pkgresults
+
+ return buildres
+