Commit f2260e48 authored by Adrien Di Mascio's avatar Adrien Di Mascio
Browse files

backport 0.11.5 branch

......@@ -44,6 +44,8 @@ bb0a3a17febe6c0262c899fb2e17fec674184973 cubicweb-brainomics-debian-version-0.11
07979b039ecfc011f3396ae7d7188695c0f99144 cubicweb-brainomics-centos-version-0.11.4-1
07979b039ecfc011f3396ae7d7188695c0f99144 cubicweb-brainomics-version-0.11.4
07979b039ecfc011f3396ae7d7188695c0f99144 cubicweb-brainomics-debian-version-0.11.4-1
cd2454cc5cf8ddbe9fc2dd13464fc5f9aa736d96 cubicweb-brainomics-version-0.11.5
cd2454cc5cf8ddbe9fc2dd13464fc5f9aa736d96 cubicweb-brainomics-debian-version-0.11.5-1
ab0c557dd3ad5fd7e5ea9709647af760b2b2f49e cubicweb-brainomics-version-0.12.0
ab0c557dd3ad5fd7e5ea9709647af760b2b2f49e cubicweb-brainomics-debian-version-0.12.0-1
ab0c557dd3ad5fd7e5ea9709647af760b2b2f49e cubicweb-brainomics-centos-version-0.12.0-1
......@@ -4,6 +4,12 @@ cubicweb-brainomics (0.12.0-1) unstable; urgency=low
-- Adrien Di Mascio <Adrien.DiMascio@logilab.fr> Fri, 24 Oct 2014 20:26:57 +0200
cubicweb-brainomics (0.11.5-1) unstable; urgency=low
* new upstream release
-- Vladimir Popescu <vladimir.popescu@logilab.fr> Wed, 15 Oct 2014 12:25:04 +0200
cubicweb-brainomics (0.11.4-1) unstable; urgency=low
* new upstream release
......
......@@ -34,35 +34,6 @@ ZIP_DOWNLOADABLE = ('Scan', 'GenomicMeasure')
ALL_DOWNLOADABLE = set(CSV_DOWNLOADABLE + XCEDE_DOWNLOADABLE + ZIP_DOWNLOADABLE)
###############################################################################
### UTILITY FUNCTIONS #########################################################
###############################################################################
def zipfiles(filepaths):
"""generates a zip archive from `filepaths`
:param filepaths: is a dictionary mapping basename (as it will appear in the
archive) to corresponding absolute filepath (where it must
read from on the filesystem)
:return: a couple fileobj, filepath where `fileobj` is a standard python
open file objet on the generated archive, and `filepath` is an
absolute file path to this archive on the filesystem
"""
fd, archive_filepath = tempfile.mkstemp()
try:
noext_archivename = osp.splitext(DataZipView.archive_name)[0]
with closing(ZipFile(archive_filepath, "w", ZIP_DEFLATED, True)) as zip:
for filename, subj, _fileobj in filepaths:
zip.writestr('%s/%s/%s' % (noext_archivename, subj, filename), _fileobj.read())
fileobj = os.fdopen(fd)
fileobj.seek(0)
return fileobj, archive_filepath
except:
os.close(fd)
os.unlink(archive_filepath)
raise
###############################################################################
### ZIP VIEWS #################################################################
###############################################################################
......@@ -74,21 +45,54 @@ class DataZipView(EntityView):
binary = True
archive_name = 'brainomics_data.zip'
def _zipfiles(self, filepaths):
"""generates a zip archive from `filepaths`
:param filepaths: is a set containing tuples with relative file paths
as they appear in the archive, and CubicWeb file
objects, whose content is put in the archive.
:return: a couple fileobj, filepath where `fileobj` is a standard python
open file objet on the generated archive, and `filepath` is an
absolute file path to this archive on the filesystem
"""
fd, archive_filepath = tempfile.mkstemp()
try:
noext_archivename = osp.splitext(self.archive_name)[0]
with closing(ZipFile(archive_filepath, "w", ZIP_DEFLATED, True)) as zip:
for filename, gmes_type, subjs, _fileobj in filepaths:
for subj in subjs:
zip.writestr('%s/%s/%s/%s' % (noext_archivename, gmes_type,
subj, filename),
_fileobj.read())
fileobj = os.fdopen(fd)
fileobj.seek(0)
return fileobj, archive_filepath
except:
os.close(fd)
os.unlink(archive_filepath)
raise
def set_request_content_type(self):
self._cw.set_content_type('application/zip', filename=self.archive_name)
def make_entity_labels(self, entity, prefix):
return ('{0}_{1}'.format(prefix, entity.concerns[0].identifier),)
def call(self):
if not self.cw_rset:
return
filepaths = set()
prefix = self._cw._('Subject')
for entity in self.cw_rset.entities():
subj = self.make_entity_labels(entity, prefix)
for _file in entity.results_files:
if _file.__regid__ == 'FileSet':
for _f in _file.file_entries:
filepaths.add(_file.dc_title(), subj, _f)
filepaths.add((_file.dc_title(), entity.dc_title(), subj, _f))
else:
filepaths.add(_file.dc_title(), subj, _file)
fileobj, archive_filepath = zipfiles(list(filepaths))
filepaths.add((_file.dc_title(), entity.dc_title(), subj, _file))
fileobj, archive_filepath = self._zipfiles(list(filepaths))
try:
self.w(fileobj.read())
finally:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment