When complexity creeps up, a simple Bash script can quickly become a very complex, unmaintainable piece of code.
Integrating the osc command into a Python script is an easy alternative to Bash when automating fairly complex tasks. It's very easy to integrate osc in your own python code.
You need to import 2 Packages.</code>
conf: Allow the access to the osc's configuration.[[1]]
core: Provide Functions to communicate with the OBS API.[[2]]
OBS API documentation is available here
Here, a simple example.
#!/usr/bin/python # Authors Ronan Le Martret (Intel OTC) # ronan@fridu.net # Date 8 Aug 2011 # License GLPv2 # This Python script # list of the packages of a project, # get the status, and so, if the status is "failed", rebuild the package.</code> from osc import conf from osc import core from xml.etree import ElementTree if __name__ == '__main__': apiurl="http://obsserver:81" prj="MeeGo:1.2.0:oss" repos="standard" arch="i586" #init the osc's configuration. aConf=conf.get_config() # Use directly the core fonction. list_package=core.meta_get_packagelist(apiurl, prj) for package in list_package: url=apiurl+"/build/"+prj+"/"+repos+"/"+arch+"/"+package+"/_status" # You can also use directly the obs API directly. aElement=ElementTree.fromstring(core.http_request("GET", url).read()) code=aElement.attrib["code"] print "code",code, if code=="failed": print "rebuild" core.rebuild(apiurl, prj, package, repos, arch) else: print
For access only, you can also use python-buildservice
python-buildservice documentation is available here [[3]]
--Ronan Le Martret Intel OpenSource Technology Centre 12:46, 8 August 2011 (UTC)