1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-12-26 09:56:13 +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:
Marcus Hüwe 2009-04-09 15:52:59 +00:00
parent 92759ad082
commit 8282e232d8
2 changed files with 23 additions and 33 deletions

View File

@ -2686,21 +2686,13 @@ Please submit there instead, or use --nodevelproject to force direct submission.
raise oscerr.WrongArgs('Wrong number of arguments.')
rev, dummy = parseRevisionOption(opts.revision)
import tempfile
(fd, filename) = tempfile.mkstemp(prefix = 'osc_%s.' % args[2], dir = '/tmp')
query = ''
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!
###############################################################################

View File

@ -2791,27 +2791,25 @@ 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):
"""
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):
"""prints out the buildlog on stdout"""
try:
while True:
u = makeurl(apiurl, ['build', prj, platform, arch, package, '_log?nostream=1&start=%s' % offset])
f = http_GET(u)
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
query = {'nostream' : '1', 'start' : '%s' % offset}
u = makeurl(apiurl, ['build', prj, platform, arch, package, '_log'], query=query)
for data in streamfile(u):
print data
def get_buildinfo(apiurl, prj, package, platform, arch, specfile=None, addlist=None):
query = []