mirror of
https://github.com/openSUSE/osc.git
synced 2025-08-12 18:24:04 +02:00
Merge branch 'fix_IncompleteRead' of https://github.com/lethliel/osc
Retry 3 times in print_buildlog in case of an incomplete read. (Instead of 3, the "http_retries" config option might be more appropriate.)
This commit is contained in:
27
osc/core.py
27
osc/core.py
@@ -30,6 +30,7 @@ try:
|
|||||||
from urllib.request import pathname2url, install_opener, urlopen
|
from urllib.request import pathname2url, install_opener, urlopen
|
||||||
from urllib.request import Request as URLRequest
|
from urllib.request import Request as URLRequest
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
from http.client import IncompleteRead
|
||||||
except ImportError:
|
except ImportError:
|
||||||
#python 2.x
|
#python 2.x
|
||||||
from urlparse import urlsplit, urlunsplit, urlparse
|
from urlparse import urlsplit, urlunsplit, urlparse
|
||||||
@@ -37,6 +38,7 @@ except ImportError:
|
|||||||
from urllib2 import HTTPError, install_opener, urlopen
|
from urllib2 import HTTPError, install_opener, urlopen
|
||||||
from urllib2 import Request as URLRequest
|
from urllib2 import Request as URLRequest
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
|
from httplib import IncompleteRead
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -5962,6 +5964,7 @@ def get_prj_results(apiurl, prj, hide_legend=False, csv=False, status_filter=Non
|
|||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def streamfile(url, http_meth = http_GET, bufsize=8192, data=None, progress_obj=None, text=None):
|
def streamfile(url, http_meth = http_GET, bufsize=8192, data=None, progress_obj=None, text=None):
|
||||||
"""
|
"""
|
||||||
performs http_meth on url and read bufsize bytes from the response
|
performs http_meth on url and read bufsize bytes from the response
|
||||||
@@ -6025,6 +6028,11 @@ def buildlog_strip_time(data):
|
|||||||
def print_buildlog(apiurl, prj, package, repository, arch, offset=0, strip_time=False, last=False):
|
def print_buildlog(apiurl, prj, package, repository, arch, offset=0, strip_time=False, last=False):
|
||||||
"""prints out the buildlog on stdout"""
|
"""prints out the buildlog on stdout"""
|
||||||
|
|
||||||
|
def print_data(data, strip_time=False):
|
||||||
|
if strip_time:
|
||||||
|
data = buildlog_strip_time(data)
|
||||||
|
sys.stdout.write(data.translate(all_bytes, remove_bytes))
|
||||||
|
|
||||||
# to protect us against control characters
|
# to protect us against control characters
|
||||||
import string
|
import string
|
||||||
all_bytes = string.maketrans('', '')
|
all_bytes = string.maketrans('', '')
|
||||||
@@ -6033,15 +6041,24 @@ def print_buildlog(apiurl, prj, package, repository, arch, offset=0, strip_time=
|
|||||||
query = {'nostream' : '1', 'start' : '%s' % offset}
|
query = {'nostream' : '1', 'start' : '%s' % offset}
|
||||||
if last:
|
if last:
|
||||||
query['last'] = 1
|
query['last'] = 1
|
||||||
|
retry_count = 0
|
||||||
while True:
|
while True:
|
||||||
query['start'] = offset
|
query['start'] = offset
|
||||||
start_offset = offset
|
start_offset = offset
|
||||||
u = makeurl(apiurl, ['build', prj, repository, arch, package, '_log'], query=query)
|
u = makeurl(apiurl, ['build', prj, repository, arch, package, '_log'], query=query)
|
||||||
for data in streamfile(u, bufsize="line"):
|
try:
|
||||||
offset += len(data)
|
for data in streamfile(u, bufsize="line"):
|
||||||
if strip_time:
|
offset += len(data)
|
||||||
data = buildlog_strip_time(data)
|
print_data(data, strip_time)
|
||||||
sys.stdout.write(data.translate(all_bytes, remove_bytes))
|
except IncompleteRead as e:
|
||||||
|
if retry_count >= 3:
|
||||||
|
raise e
|
||||||
|
retry_count += 1
|
||||||
|
data = e.partial
|
||||||
|
if len(data):
|
||||||
|
offset += len(data)
|
||||||
|
print_data(data, strip_time)
|
||||||
|
continue
|
||||||
if start_offset == offset:
|
if start_offset == offset:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user