osclib/stagingapi: buildlog_get(): support negative offset.

Derive real offset from log size determined via additional API call.
This commit is contained in:
Jimmy Berry 2019-09-24 08:39:02 -05:00
parent 83f1d51c3b
commit c8663d83af

View File

@ -922,6 +922,14 @@ class StagingAPI(object):
all_bytes = bytes.maketrans(b'', b'')
remove_bytes = all_bytes[:8] + all_bytes[14:32] # accept tabs and newlines
path = ['build', prj, repository, arch, package, '_log']
if offset < 0:
url = makeurl(self.apiurl, path, {'view': 'entry'})
root = ET.parse(http_GET(url)).getroot()
size = root.xpath('entry[@name="_log"]/@size')
if size:
offset += int(size[0])
query = {'nostream': '1', 'start': '%s' % offset}
if last:
query['last'] = 1
@ -929,7 +937,7 @@ class StagingAPI(object):
while True:
query['start'] = offset
start_offset = offset
u = makeurl(self.apiurl, ['build', prj, repository, arch, package, '_log'], query=query)
u = makeurl(self.apiurl, path, query)
for data in streamfile(u, bufsize="line"):
offset += len(data)
if strip_time: