Allow to specify a place where to unpack zip data

Now unpack_zip_archive_in_memory always unpacks data in
folder called 'content'. To add more flexibility we add
new parameter that defines where to unpack the data.

Change-Id: Ieb2f24776293a1890d755cddc458511b16f8eb82
This commit is contained in:
Mike Fedosin 2017-07-25 17:18:40 +03:00
parent dd61d8fc53
commit 5ef746ab9e
1 changed files with 5 additions and 4 deletions

View File

@ -102,12 +102,13 @@ def upload_content_file(context, af, data, blob_dict, key_name,
af.update_blob(context, af.id, blob_dict, getattr(af, blob_dict))
def unpack_zip_archive_in_memory(context, af, fd):
"""Unpack zip archive in memory.
def unpack_zip_archive_in_memory(context, af, field_name, fd):
"""Unpack zip archive in memory and write its content to artifact folder.
:param context: user context
:param af: artifact object
:param fd: file
:param field_name: blob dict name where to unpack the data
:param fd: zip archive
:return io.BytesIO object - simple stream of in-memory bytes, None
"""
flobj = io.BytesIO(fd.read())
@ -122,6 +123,6 @@ def unpack_zip_archive_in_memory(context, af, fd):
if not name.endswith('/'):
upload_content_file(
context, af, utils.BlobIterator(zip_ref.read(name)),
'content', name)
field_name, name)
flobj.seek(0)
return flobj, None