mirror of
https://github.com/openSUSE/osc.git
synced 2024-12-27 18:26:15 +01:00
- added streamfile() method
- print_buildlog: use streamfile() to retrieve the buildlog - do_cat: use streamfile() to retrieve a file - there's no need to have a tempfile or to read the entire file into memory anymore
This commit is contained in:
parent
92759ad082
commit
8282e232d8
@ -2686,21 +2686,13 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
raise oscerr.WrongArgs('Wrong number of arguments.')
|
raise oscerr.WrongArgs('Wrong number of arguments.')
|
||||||
rev, dummy = parseRevisionOption(opts.revision)
|
rev, dummy = parseRevisionOption(opts.revision)
|
||||||
|
|
||||||
import tempfile
|
query = ''
|
||||||
(fd, filename) = tempfile.mkstemp(prefix = 'osc_%s.' % args[2], dir = '/tmp')
|
if opts.revision:
|
||||||
|
query = 'rev=%s' % opts.revision
|
||||||
|
u = makeurl(conf.config['apiurl'], ['source', args[0], args[1], args[2]], query=query)
|
||||||
|
for data in streamfile(u):
|
||||||
|
sys.stdout.write(data)
|
||||||
|
|
||||||
get_source_file(conf.config['apiurl'], args[0], args[1], args[2],
|
|
||||||
targetfilename=filename, revision=rev)
|
|
||||||
|
|
||||||
# FIXME: stream directly without temp file and without keeping the entire file in memory
|
|
||||||
f = open(filename, 'rb')
|
|
||||||
sys.stdout.write(f.read())
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
try:
|
|
||||||
os.unlink(filename)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
# fini!
|
# fini!
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
36
osc/core.py
36
osc/core.py
@ -2791,27 +2791,25 @@ 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):
|
||||||
|
"""
|
||||||
|
performs http_meth on url and read bufsize bytes from the response
|
||||||
|
until EOF is reached. After each read bufsize bytes are yielded to the
|
||||||
|
caller.
|
||||||
|
"""
|
||||||
|
f = http_meth.__call__(url)
|
||||||
|
data = f.read(bufsize)
|
||||||
|
while len(data):
|
||||||
|
yield data
|
||||||
|
data = f.read(bufsize)
|
||||||
|
|
||||||
|
|
||||||
def print_buildlog(apiurl, prj, package, platform, arch, offset = 0):
|
def print_buildlog(apiurl, prj, package, platform, arch, offset = 0):
|
||||||
"""prints out the buildlog on stdout"""
|
"""prints out the buildlog on stdout"""
|
||||||
try:
|
query = {'nostream' : '1', 'start' : '%s' % offset}
|
||||||
while True:
|
u = makeurl(apiurl, ['build', prj, platform, arch, package, '_log'], query=query)
|
||||||
u = makeurl(apiurl, ['build', prj, platform, arch, package, '_log?nostream=1&start=%s' % offset])
|
for data in streamfile(u):
|
||||||
f = http_GET(u)
|
print data
|
||||||
start_offset = offset
|
|
||||||
while True:
|
|
||||||
log_chunk = f.read(8192)
|
|
||||||
offset += len(log_chunk)
|
|
||||||
print log_chunk,
|
|
||||||
if not len(log_chunk):
|
|
||||||
break
|
|
||||||
if start_offset == offset:
|
|
||||||
break
|
|
||||||
|
|
||||||
except urllib2.HTTPError, e:
|
|
||||||
print >>sys.stderr, 'Can\'t get logfile'
|
|
||||||
print >>sys.stderr, e
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def get_buildinfo(apiurl, prj, package, platform, arch, specfile=None, addlist=None):
|
def get_buildinfo(apiurl, prj, package, platform, arch, specfile=None, addlist=None):
|
||||||
query = []
|
query = []
|
||||||
|
Loading…
Reference in New Issue
Block a user