1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# -*- coding: utf-8 -*-
"""
Python OBS 'source' API
~~~~~~~~~~~~~~~~~~~~~~~
This module provides the ObsSourceAPI class used for accessing
the `Open Build Service <https://openbuildservice.org/>'_ APIs
related to `sources <https://build.opensuse.org/apidocs/index>`_.
: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/<prj>/<repo>/<arch>/<pkg>/<binaryname>?<params>
"""
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)
|