# -*- coding: utf-8 -*- """ Python OBS 'source' API ~~~~~~~~~~~~~~~~~~~~~~~ This module provides the ObsSourceAPI class used for accessing the `Open Build Service '_ APIs related to `sources `_. :copyright: Copyright (c) 2015-2020 Scott Bahling This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program (see the file COPYING); if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA :license: GPL-2.0, see COPYING for details """ from obsapi.httpapi import ObsHttpApi class ObsBuildApi(ObsHttpApi): """Class for low level access to OBS 'build' apis. This class of the provides get, put, post methods for accessing Open Build Service APIs under base `/build` api route. Attributes """ rootapi = '/build/' def __get(self, *args, **kwargs): return super(ObsBuildApi, self).get(*args, **kwargs) def __put(self, *args, **kwargs): return super(ObsBuildApi, self).put(*args, **kwargs) def __post(self, *args, **kwargs): return super(ObsBuildApi, self).post(*args, **kwargs) def get(self, prj=None, repo=None, arch=None, pkg=None, binaryname=None, **kwargs): """ Send GET request to the OBS API under the '/build' route. :param prj: OBS project name (Default value = None) :param repo: Project repo name (Default value = None) :param arch: Build architecture (Default value = None) :param pkg: OBS package name (Default value = None) :param binaryname: Build result binary file name (Default value = None) :param **kwargs: HTTP query key/value pairs :returns: content payload of the HTTP response as string or bytes Calls GET build/////? """ errormsg = [] if binaryname and not pkg: errormsg.append('Expect pkg argument when passing binaryname') if pkg and not arch: errormsg.append('Expect arch argument when passing pkg') if arch and not repo: errormsg.append('Expect repo argument when passing arch') if repo and not prj: errormsg.append('Expect prj argument when passing repo') if errormsg: raise ValueError('\n'.join(errormsg)) binary_get = (binaryname is not None) return self.__get(prj, repo, arch, pkg, binaryname, binary_get=binary_get, **kwargs) def get_builddepinfo(self, prj, repo, arch, pkg): return self.__get(prj, repo, arch, '_builddepinfo', package=pkg) def get_buildconfig(self, prj, repo): return self.__get(prj, repo, '_buildconfig') def get_buildinfo(self, prj, repo, arch, pkg): return self.__get(prj, repo, arch, pkg, '_buildinfo') def get_jobhistory(self, prj, repo, arch, pkg=None, code=None, limit=None): return self.__get(prj, repo, arch, '_jobhistory', package=pkg, code=code, limit=limit) def get_result(self, prj): return self.__get(prj, '_result') def get_workstatus(self): return self.__get('_workerstatus') def get_history(self, prj, repo, arch, pkg): return self.__get(prj, repo, arch, pkg, '_history') def get_reason(self, prj, repo, arch, pkg): return self.__get(prj, repo, arch, pkg, '_reason') def get_jobstatus(self, prj, repo, arch, pkg): return self.__get(prj, repo, arch, pkg, '_jobstatus') def get_status(self, prj, repo, arch, pkg): return self.__get(prj, repo, arch, pkg, '_status') def get_log(self, prj, repo, arch, pkg, **kwargs): return self.__get(prj, repo, arch, pkg, '_log', **kwargs) def get_repository(self, prj, repo, arch, binaryname=None): # Important! We call self.get() to handle binary get properly return self.get(prj, repo, arch, '_repository', binaryname) def put_repository(self, prj, repo, arch, filename, data): return self.__put(prj, repo, arch, '_repository', filename, data=data) def post(self, prj, repo, arch, pkg, data, **kwargs): print(prj, repo, arch, pkg) return self.__post(prj, repo, arch, pkg, data=data, **kwargs)