-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5220 from jmchilton/upload_2.0
Hierarchical upload API optimized for folders & collections.
- Loading branch information
Showing
37 changed files
with
2,040 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from galaxy.datatypes import sniff | ||
from galaxy.datatypes.binary import Binary | ||
|
||
|
||
class UploadProblemException(Exception): | ||
|
||
def __init__(self, message): | ||
self.message = message | ||
|
||
|
||
def handle_unsniffable_binary_check(data_type, ext, path, name, is_binary, requested_ext, check_content, registry): | ||
"""Return modified values of data_type and ext if unsniffable binary encountered. | ||
Throw UploadProblemException if content problems or extension mismatches occur. | ||
Precondition: check_binary called returned True. | ||
""" | ||
if is_binary or registry.is_extension_unsniffable_binary(requested_ext): | ||
# We have a binary dataset, but it is not Bam, Sff or Pdf | ||
data_type = 'binary' | ||
parts = name.split(".") | ||
if len(parts) > 1: | ||
ext = parts[-1].strip().lower() | ||
is_ext_unsniffable_binary = registry.is_extension_unsniffable_binary(ext) | ||
if check_content and not is_ext_unsniffable_binary: | ||
raise UploadProblemException('The uploaded binary file contains inappropriate content') | ||
|
||
elif is_ext_unsniffable_binary and requested_ext != ext: | ||
err_msg = "You must manually set the 'File Format' to '%s' when uploading %s files." % (ext, ext) | ||
raise UploadProblemException(err_msg) | ||
return data_type, ext | ||
|
||
|
||
def handle_sniffable_binary_check(data_type, ext, path, registry): | ||
"""Return modified values of data_type and ext if sniffable binary encountered. | ||
Precondition: check_binary called returned True. | ||
""" | ||
# Sniff the data type | ||
guessed_ext = sniff.guess_ext(path, registry.sniff_order) | ||
# Set data_type only if guessed_ext is a binary datatype | ||
datatype = registry.get_datatype_by_extension(guessed_ext) | ||
if isinstance(datatype, Binary): | ||
data_type = guessed_ext | ||
ext = guessed_ext | ||
|
||
return data_type, ext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.