Merge pull request #9500 from mvdbeek/keep_status_code_on_message_exception

[20.01] Keep status code on message exception and history import/export fixes
This commit is contained in:
John Chilton
2020-03-26 09:33:01 -04:00
committed by GitHub
4 changed files with 13 additions and 17 deletions
+1 -1
View File
@@ -1939,7 +1939,7 @@ class JobWrapper(HasResourceParameters):
self.output_paths = [t[2] for t in results]
self.output_hdas_and_paths = dict([(t[0], t[1:]) for t in results])
if special:
false_path = dataset_path_rewriter.rewrite_dataset_path(special.dataset, 'output')
false_path = dataset_path_rewriter.rewrite_dataset_path(special, 'output')
dsp = DatasetPath(special.dataset.id, special.dataset.file_name, false_path)
self.output_paths.append(dsp)
return self.output_paths
@@ -1,6 +1,9 @@
<tool id="__IMPORT_HISTORY__" name="Import History" version="0.1" tool_type="import_history">
<tool id="__IMPORT_HISTORY__" name="Import History" version="0.1" tool_type="import_history" profile="16.04">
<type class="ImportHistoryTool" module="galaxy.tools"/>
<action module="galaxy.tools.actions.history_imp_exp" class="ImportHistoryToolAction"/>
<requirements>
<requirement type="package" version="2.23.0">requests</requirement>
</requirements>
<command>#from base64 import b64encode#
python '$__tool_directory__/unpack_tar_gz_archive.py'
'${ b64encode(str($__ARCHIVE_SOURCE__).encode('utf-8')).decode('utf-8')}'
@@ -10,7 +10,6 @@ from __future__ import print_function
import math
import optparse
import os
import sys
import tarfile
import tempfile
from base64 import b64decode
@@ -26,22 +25,18 @@ def url_to_file(url, dest_file):
"""
Transfer a file from a remote URL to a temporary file.
"""
try:
url_reader = requests.get(url, stream=True)
CHUNK = 10 * 1024 # 10k
total = 0
fp = open(dest_file, 'wb')
url_reader = requests.get(url, stream=True)
assert url_reader.ok, "History import failed, server returned '%s'" % url_reader.reason
CHUNK = 10 * 1024 # 10k
total = 0
with open(dest_file, 'wb') as fp:
for chunk in url_reader.iter_content(chunk_size=CHUNK):
if chunk:
fp.write(chunk)
total += CHUNK
if total > MAX_SIZE:
break
fp.close()
return dest_file
except Exception as e:
print("Exception getting file from URL: %s" % e, file=sys.stderr)
return None
return dest_file
def check_archive(archive_file, dest_dir):
@@ -96,7 +91,4 @@ if __name__ == "__main__":
parser.add_option('-F', '--file', dest='is_file', action="store_true", help='Source is a file.')
parser.add_option('-e', '--encoded', dest='is_b64encoded', action="store_true", default=False, help='Source and destination dir values are base64 encoded.')
(options, args) = parser.parse_args()
try:
main(options, args)
except Exception as e:
print("Error unpacking tar/gz archive: %s" % e, file=sys.stderr)
main(options, args)
+1
View File
@@ -106,6 +106,7 @@ class WebApplication(base.WebApplication):
if isinstance(e, MessageException):
# In the case of a controller exception, sanitize to make sure
# unsafe html input isn't reflected back to the user
trans.response.status = e.status_code
return trans.show_message(sanitize_html(e.err_msg), e.type)
def make_body_iterable(self, trans, body):