Skip to content

Commit

Permalink
Merge branch 'fix_IncompleteRead' of https://github.com/lethliel/osc
Browse files Browse the repository at this point in the history
Retry 3 times in print_buildlog in case of an incomplete read. (Instead
of 3, the "http_retries" config option might be more appropriate.)
  • Loading branch information
marcus-h committed Apr 25, 2018
2 parents 22f0c21 + 1caa825 commit cbd1064
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions osc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@
from urllib.request import pathname2url, install_opener, urlopen
from urllib.request import Request as URLRequest
from io import StringIO
from http.client import IncompleteRead
except ImportError:
#python 2.x
from urlparse import urlsplit, urlunsplit, urlparse
from urllib import pathname2url, quote_plus, urlencode, unquote
from urllib2 import HTTPError, install_opener, urlopen
from urllib2 import Request as URLRequest
from cStringIO import StringIO
from httplib import IncompleteRead


try:
Expand Down Expand Up @@ -5962,6 +5964,7 @@ def get_prj_results(apiurl, prj, hide_legend=False, csv=False, status_filter=Non
return r



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
Expand Down Expand Up @@ -6025,6 +6028,11 @@ def buildlog_strip_time(data):
def print_buildlog(apiurl, prj, package, repository, arch, offset=0, strip_time=False, last=False):
"""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
import string
all_bytes = string.maketrans('', '')
Expand All @@ -6033,15 +6041,24 @@ def print_buildlog(apiurl, prj, package, repository, arch, offset=0, strip_time=
query = {'nostream' : '1', 'start' : '%s' % offset}
if last:
query['last'] = 1
retry_count = 0
while True:
query['start'] = offset
start_offset = offset
u = makeurl(apiurl, ['build', prj, repository, arch, package, '_log'], query=query)
for data in streamfile(u, bufsize="line"):
offset += len(data)
if strip_time:
data = buildlog_strip_time(data)
sys.stdout.write(data.translate(all_bytes, remove_bytes))
try:
for data in streamfile(u, bufsize="line"):
offset += len(data)
print_data(data, strip_time)
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:
break

Expand Down

0 comments on commit cbd1064

Please sign in to comment.