summaryrefslogtreecommitdiff
path: root/obsapi/core.py
diff options
context:
space:
mode:
authorScott Bahling <sbahling@suse.com>2020-02-12 18:38:33 +0100
committerScott Bahling <sbahling@suse.com>2020-02-12 18:38:33 +0100
commit7806de5f05bbc153b8405f1e693e1ae202e2a54c (patch)
tree44097318002add0f5e076cb057d10e9edca06ba4 /obsapi/core.py
parent9b0d40c28f86e58df131b7971e2c0640d77a01a1 (diff)
downloadobsapi-7806de5f05bbc153b8405f1e693e1ae202e2a54c.tar.gz
obsapi-7806de5f05bbc153b8405f1e693e1ae202e2a54c.tar.xz
obsapi-7806de5f05bbc153b8405f1e693e1ae202e2a54c.zip
Implement sub-api callbackso
When an api object makes an API request to the OBS server, in addition to returning the results, it sends a reference to itself to the registered callback function (if set). We use this to track the last api object called so we can access the last raw request response.
Diffstat (limited to 'obsapi/core.py')
-rw-r--r--obsapi/core.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/obsapi/core.py b/obsapi/core.py
index c81f699..209aab2 100644
--- a/obsapi/core.py
+++ b/obsapi/core.py
@@ -8,6 +8,7 @@ from obsapi.sourceapi import ObsSourceApi
from obsapi.buildapi import ObsBuildApi
from obsapi.repoflags import RepoFlags
from obsapi.fileinfo import FileInfo
+from .null import Null
LSItem = namedtuple('LSItem', 'name md5 size mtime')
@@ -34,13 +35,27 @@ class ObsApi(object):
def __init__(self, apiurl=None):
self.apiurl = apiurl or DEFAULTAPIURL
+ self.lastapi = Null
+ self._response = Null
+
+ # init the source api
self.source = ObsSourceApi(self.apiurl)
- self.build = ObsBuildApi(self.apiurl)
self.source.retries = 0
self.source.verify_ssl = True
+ self.source.set_callback(self._api_callback)
+
+ # init the build api
+ self.build = ObsBuildApi(self.apiurl)
self.build.retries = 0
self.build.verify_ssl = True
- self.lastapi = None
+ self.build.set_callback(self._api_callback)
+
+ def _api_callback(self, api_instance):
+ self.lastapi = api_instance
+
+ @property
+ def response(self):
+ return self.lastapi.response
def get_meta(self, prj, pkg=None):
return self.source.get_meta(prj, pkg=pkg)