Skip to content

Commit

Permalink
Remove unncecessary implementations of display_data
Browse files Browse the repository at this point in the history
These were not updated to use `_download_filename`,
and so this fixes the download name for collection elements
to include the element identifier.
Note that the Data class should handle composite data just
fine.
  • Loading branch information
mvdbeek committed Nov 5, 2018
1 parent 69b4471 commit 3be8d66
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 59 deletions.
12 changes: 1 addition & 11 deletions lib/galaxy/datatypes/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from galaxy import util
from galaxy.datatypes import metadata
from galaxy.datatypes.metadata import DictParameter, ListParameter, MetadataElement, MetadataParameter
from galaxy.util import FILENAME_VALID_CHARS, nice_size, sqlite
from galaxy.util import nice_size, sqlite
from galaxy.util.checkers import is_bz2, is_gzip
from . import data, dataproviders

Expand Down Expand Up @@ -59,16 +59,6 @@ def get_mime(self):
"""Returns the mime type of the datatype"""
return 'application/octet-stream'

def display_data(self, trans, dataset, preview=False, filename=None, to_ext=None, **kwd):
trans.response.set_content_type(dataset.get_mime())
trans.log_event("Display dataset id: %s" % str(dataset.id))
trans.response.headers['Content-Length'] = int(os.stat(dataset.file_name).st_size)
to_ext = dataset.extension
fname = ''.join(c in FILENAME_VALID_CHARS and c or '_' for c in dataset.name)[0:150]
trans.response.set_content_type("application/octet-stream") # force octet-stream so Safari doesn't append mime extensions to filename
trans.response.headers["Content-Disposition"] = 'attachment; filename="Galaxy%s-[%s].%s"' % (dataset.hid, fname, to_ext)
return open(dataset.file_name, mode='rb')


class Ab1(Binary):
"""Class describing an ab1 binary sequence file"""
Expand Down
9 changes: 5 additions & 4 deletions lib/galaxy/datatypes/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,11 @@ def to_archive(self, trans, dataset, name=""):
return zip(file_paths, rel_paths)

def display_data(self, trans, data, preview=False, filename=None, to_ext=None, **kwd):
""" Old display method, for transition - though still used by API and
test framework. Datatypes should be very careful if overridding this
method and this interface between datatypes and Galaxy will likely
change.
"""
Displays data in central pane if preview is `True`, else handles download.
Datatypes should be very careful if overridding this method and this interface
between datatypes and Galaxy will likely change.
TOOD: Document alternatives to overridding this method (data
providers?).
Expand Down
8 changes: 0 additions & 8 deletions lib/galaxy/datatypes/molecules.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,14 +423,6 @@ def display_peek(self, dataset):
except Exception:
return "OpenBabel Fastsearch Index"

def display_data(self, trans, data, preview=False, filename=None,
to_ext=None, **kwd):
"""Apparently an old display method, but still gets called.
This allows us to format the data shown in the central pane via the "eye" icon.
"""
return b"This is a OpenBabel Fastsearch format. You can speed up your similarity and substructure search with it."

def get_mime(self):
"""Returns the mime type of the datatype (pretend it is text for peek)"""
return 'text/plain'
Expand Down
36 changes: 0 additions & 36 deletions lib/galaxy/datatypes/neo4j.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
Neo4j Composite Dataset
"""
import logging
import os
import shutil
import sys

from galaxy.datatypes.data import Data
from galaxy.datatypes.images import Html
from galaxy.datatypes.metadata import MetadataElement
from galaxy.util import FILENAME_VALID_CHARS

gal_Log = logging.getLogger(__name__)
verbose = True
Expand Down Expand Up @@ -61,39 +58,6 @@ def display_peek(self, dataset):
except Exception:
return "NEO4J database (multiple files)"

def display_data(self, trans, data, preview=False, filename=None,
to_ext=None, size=None, offset=None, **kwd):
"""Documented as an old display method, but still gets called via tests etc
This allows us to format the data shown in the central pane via the "eye" icon.
"""
if not preview:
trans.response.set_content_type(data.get_mime())
trans.log_event("Display dataset id: %s" % str(data.id))

# the target directory name
neo4j_dir_name = '/dataset_{}_files'.format(
data.dataset.id)
dir_name = str(os.path.dirname(
trans.app.object_store.get_filename(data.dataset))) + neo4j_dir_name

# generate unique filename for this dataset
fname = ''.join(
c in FILENAME_VALID_CHARS and c or '_' for c in data.name)[0:150]

# zip the target directory (dir_name) using the fname
shutil.make_archive(fname, 'zip', dir_name)
download_zip = fname + '.zip'

# setup headers for the download
trans.response.headers['Content-Length'] = int(
os.stat(download_zip).st_size)
# force octet-stream so Safari doesn't append mime extensions to filename
trans.response.set_content_type("application/octet-stream")
trans.response.headers["Content-Disposition"] = 'attachment; filename="Galaxy%s-[%s].%s"' % \
(data.hid,
download_zip, "zip")
return open(download_zip, mode='rb')


class Neo4jDB(Neo4j, Data):
"""Class for neo4jDB database files."""
Expand Down

0 comments on commit 3be8d66

Please sign in to comment.