Skip to content

Commit

Permalink
Python3: open 2 files in binary mode
Browse files Browse the repository at this point in the history
  • Loading branch information
nsoranzo committed Jan 15, 2019
1 parent b23a2a4 commit f70d24a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
24 changes: 12 additions & 12 deletions lib/galaxy/webapps/galaxy/api/datasets.py
Expand Up @@ -351,23 +351,23 @@ def display(self, trans, history_content_id, history_id,
else:
file_path = hda.file_name
rval = open(file_path, 'rb')

else:
display_kwd = kwd.copy()
if 'key' in display_kwd:
del display_kwd["key"]
rval = hda.datatype.display_data(trans, hda, preview, filename, to_ext, **display_kwd)

except Exception as exception:
log.error("Error getting display data for dataset (%s) from history (%s): %s",
history_content_id, history_id, str(exception), exc_info=True)
except Exception as e:
log.exception("Error getting display data for dataset (%s) from history (%s)",
history_content_id, history_id)
trans.response.status = 500
rval = ("Could not get display data for dataset: " + str(exception))

rval = "Could not get display data for dataset: %s" % e
return rval

@web.expose_api_raw_anonymous
def get_metadata_file(self, trans, history_content_id, history_id, metadata_file=None, **kwd):
"""
GET /api/histories/{history_id}/contents/{history_content_id}/metadata_file
"""
decoded_content_id = self.decode_id(history_content_id)
rval = ''
try:
Expand All @@ -376,12 +376,12 @@ def get_metadata_file(self, trans, history_content_id, history_id, metadata_file
fname = ''.join(c in util.FILENAME_VALID_CHARS and c or '_' for c in hda.name)[0:150]
trans.response.headers["Content-Type"] = "application/octet-stream"
trans.response.headers["Content-Disposition"] = 'attachment; filename="Galaxy%s-[%s].%s"' % (hda.hid, fname, file_ext)
return open(hda.metadata.get(metadata_file).file_name)
except Exception as exception:
log.error("Error getting metadata_file (%s) for dataset (%s) from history (%s): %s",
metadata_file, history_content_id, history_id, str(exception), exc_info=True)
return open(hda.metadata.get(metadata_file).file_name, 'rb')
except Exception as e:
log.exception("Error getting metadata_file (%s) for dataset (%s) from history (%s)",
metadata_file, history_content_id, history_id)
trans.response.status = 500
rval = ("Could not get display data for dataset: " + str(exception))
rval = "Could not get metadata for dataset: %s" % e
return rval

@web._future_expose_api_anonymous
Expand Down
4 changes: 2 additions & 2 deletions test/api/test_histories.py
Expand Up @@ -192,7 +192,7 @@ def test_import_export(self):
def test_import_metadata_regeneration(self):
history_name = "for_import_metadata_regeneration"
history_id = self.dataset_populator.new_history(name=history_name)
self.dataset_populator.new_dataset(history_id, content=open(self.test_data_resolver.get_filename("1.bam")), file_type='bam')
self.dataset_populator.new_dataset(history_id, content=open(self.test_data_resolver.get_filename("1.bam"), 'rb'), file_type='bam')
imported_history_id = self._reimport_history(history_id, history_name)
self._assert_history_length(imported_history_id, 1)
import_bam_metadata = self.dataset_populator.get_history_dataset_details(
Expand All @@ -203,7 +203,7 @@ def test_import_metadata_regeneration(self):
assert bai_metadata["file_type"] == "bam_index"
api_url = bai_metadata["download_url"].split("api/", 1)[1]
bai_response = self._get(api_url)
assert bai_response.status_code == 200
self._assert_status_code_is(bai_response, 200)
assert len(bai_response.content) > 4

def test_import_export_collection(self):
Expand Down

0 comments on commit f70d24a

Please sign in to comment.