-
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.
[WIP] Hierarchical upload API optimized for folders & collections.
Allows describing hierarchical data in JSON or inferring structure from archives or directories. Datasets or archive sources can be specified via uploads, URLs, paths (if admin && allow_path_paste), library_import_dir/user_library_import_dir, and/or FTP imports. Unlike existing API endpoints, a mix of these on a per file basis is allowed and they work seemlessly between libraries and histories. Supported "archives" include gzip, zip, bagit directories, bagit achives (with fetching and validations of downloads). The existing upload API endpoint is quite rough to work with both in terms of adding parameters (e.g. the file type and dbkey hanlding in 4563 was difficult to implement, terribly hacky, and should seemingly have been trivial) and in terms of building requests (one needs to build a tool form - not describe sensible inputs in JSON). This API is built to be intelligable from an API standpoint instead of being constrained to the older style tool form. Additionally it built with hierarchical data in mind in a way that would not be easy at all enhancing the tool form components we don't even render. This implements 5159 though much simpler YAML descriptions of data libraries should be possible basically as the API descriptions. We can replace the data library script in Ephemeris https://github.com/galaxyproject/ephemeris/blob/master/ephemeris/setup_data_libraries.py with one that converts a simple YAML file into an API call and allows many new options for free. In future PRs I'll add filtering options to this and it will serve as the backend to 4733.
- Loading branch information
Showing
25 changed files
with
996 additions
and
60 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
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
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.