download the file in 64k chunks instead of pulling the entire file into memory

This commit is contained in:
Mike Bonnet 2007-08-20 16:00:47 -04:00
parent 34737ac662
commit fec67b4f93
2 changed files with 33 additions and 5 deletions

View file

@ -4031,14 +4031,30 @@ class RootExports(object):
f.close()
return base64.encodestring(contents)
def listTaskOutput(self, taskID):
def listTaskOutput(self, taskID, stat=False):
"""List the files generated by the task with the given ID. This
will usually include one or more RPMs, and one or more log files.
If the task did not generate any files, or the output directory
for the task no longer exists, return an empty list."""
for the task no longer exists, return an empty list.
If stat is True, return a map of filename -> stat_info where stat_info
is a map containing the values of the st_* attributes returned by
os.stat()."""
taskDir = '%s/tasks/%i' % (koji.pathinfo.work(), taskID)
if os.path.isdir(taskDir):
return os.listdir(taskDir)
output = os.listdir(taskDir)
if stat:
ret = {}
for filename in output:
stat_info = os.stat(os.path.join(taskDir, filename))
stat_map = {}
for attr in dir(stat_info):
if attr.startswith('st_'):
stat_map[attr] = getattr(stat_info, attr)
ret[filename] = stat_map
return ret
else:
return output
else:
return []

View file

@ -508,14 +508,26 @@ def _sortByExtAndName(a, b):
def getfile(req, taskID, name):
server = _getServer(req)
taskID = int(taskID)
output = server.listTaskOutput(taskID, stat=True)
file_info = output.get(name)
if not file_info:
raise koji.GenericError, 'no file "%s" output by task %i' % (name, taskID)
if name.endswith('.rpm'):
req.content_type = 'application/x-rpm'
req.headers_out['Content-Disposition'] = 'attachment; filename=%s' % name
elif name.endswith('.log'):
req.content_type = 'text/plain'
return server.downloadTaskOutput(taskID, name)
req.set_content_length(file_info['st_size'])
offset = 0
while True:
content = server.downloadTaskOutput(taskID, name, offset=offset, size=65536)
if not content:
break
req.write(content)
offset += len(content)
def tags(req, start=None, order=None, childID=None):
values = _initValues(req, 'Tags', 'tags')