annotate data_source.py @ 0:fe2937ae3ee2 draft

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
author bgruening
date Wed, 13 Dec 2023 16:04:48 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
1 #!/usr/bin/env python
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
2 # Retrieves data from external data source applications and stores in a dataset file.
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
3 # Data source application parameters are temporarily stored in the dataset file.
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
4 import os
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
5 import sys
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
6 from json import (
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
7 dumps,
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
8 loads,
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
9 )
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
10 from urllib.parse import (
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
11 urlencode,
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
12 urlparse,
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
13 )
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
14 from urllib.request import urlopen
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
15
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
16 from galaxy.datatypes import sniff
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
17 from galaxy.datatypes.registry import Registry
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
18 from galaxy.jobs import TOOL_PROVIDED_JOB_METADATA_FILE
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
19 from galaxy.util import (
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
20 DEFAULT_SOCKET_TIMEOUT,
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
21 get_charset_from_http_headers,
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
22 stream_to_open_named_file,
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
23 )
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
24
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
25 GALAXY_PARAM_PREFIX = "GALAXY"
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
26 GALAXY_ROOT_DIR = os.path.realpath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
27 GALAXY_DATATYPES_CONF_FILE = os.path.join(GALAXY_ROOT_DIR, "datatypes_conf.xml")
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
28
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
29
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
30 def stop_err(msg):
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
31 sys.stderr.write(msg)
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
32 sys.exit()
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
33
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
34
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
35 def load_input_parameters(filename, erase_file=True):
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
36 datasource_params = {}
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
37 try:
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
38 json_params = loads(open(filename).read())
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
39 datasource_params = json_params.get("param_dict")
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
40 except Exception:
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
41 json_params = None
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
42 for line in open(filename):
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
43 try:
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
44 line = line.strip()
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
45 fields = line.split("\t")
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
46 datasource_params[fields[0]] = fields[1]
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
47 except Exception:
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
48 continue
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
49 if erase_file:
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
50 open(filename, "w").close() # open file for writing, then close, removes params from file
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
51 return json_params, datasource_params
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
52
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
53
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
54 def __main__():
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
55 filename = sys.argv[1]
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
56 try:
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
57 max_file_size = int(sys.argv[2])
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
58 except Exception:
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
59 max_file_size = 0
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
60
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
61 job_params, params = load_input_parameters(filename)
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
62 if job_params is None: # using an older tabular file
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
63 enhanced_handling = False
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
64 job_params = dict(param_dict=params)
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
65 job_params["output_data"] = [
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
66 dict(out_data_name="output", ext="data", file_name=filename, extra_files_path=None)
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
67 ]
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
68 job_params["job_config"] = dict(
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
69 GALAXY_ROOT_DIR=GALAXY_ROOT_DIR,
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
70 GALAXY_DATATYPES_CONF_FILE=GALAXY_DATATYPES_CONF_FILE,
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
71 TOOL_PROVIDED_JOB_METADATA_FILE=TOOL_PROVIDED_JOB_METADATA_FILE,
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
72 )
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
73 else:
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
74 enhanced_handling = True
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
75 json_file = open(
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
76 job_params["job_config"]["TOOL_PROVIDED_JOB_METADATA_FILE"], "w"
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
77 ) # specially named file for output junk to pass onto set metadata
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
78
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
79 datatypes_registry = Registry()
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
80 datatypes_registry.load_datatypes(
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
81 root_dir=job_params["job_config"]["GALAXY_ROOT_DIR"],
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
82 config=job_params["job_config"]["GALAXY_DATATYPES_CONF_FILE"],
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
83 )
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
84
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
85 URL = params.get("URL", None) # using exactly URL indicates that only one dataset is being downloaded
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
86 URL_method = params.get("URL_method", None)
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
87
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
88 for data_dict in job_params["output_data"]:
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
89 cur_filename = data_dict.get("file_name", filename)
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
90 cur_URL = params.get("%s|%s|URL" % (GALAXY_PARAM_PREFIX, data_dict["out_data_name"]), URL)
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
91 if not cur_URL or urlparse(cur_URL).scheme not in ("http", "https", "ftp"):
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
92 open(cur_filename, "w").write("")
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
93 stop_err("The remote data source application has not sent back a URL parameter in the request.")
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
94
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
95 # The following calls to urlopen() will use the above default timeout
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
96 try:
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
97 if not URL_method or URL_method == "get":
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
98 page = urlopen(cur_URL, timeout=DEFAULT_SOCKET_TIMEOUT)
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
99 elif URL_method == "post":
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
100 page = urlopen(cur_URL, urlencode(params).encode("utf-8"), timeout=DEFAULT_SOCKET_TIMEOUT)
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
101 except Exception as e:
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
102 stop_err("The remote data source application may be off line, please try again later. Error: %s" % str(e))
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
103 if max_file_size:
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
104 file_size = int(page.info().get("Content-Length", 0))
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
105 if file_size > max_file_size:
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
106 stop_err(
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
107 "The size of the data (%d bytes) you have requested exceeds the maximum allowed (%d bytes) on this server."
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
108 % (file_size, max_file_size)
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
109 )
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
110 try:
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
111 cur_filename = stream_to_open_named_file(
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
112 page,
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
113 os.open(cur_filename, os.O_WRONLY | os.O_CREAT),
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
114 cur_filename,
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
115 source_encoding=get_charset_from_http_headers(page.headers),
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
116 )
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
117 except Exception as e:
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
118 stop_err("Unable to fetch %s:\n%s" % (cur_URL, e))
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
119
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
120 # here import checks that upload tool performs
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
121 if enhanced_handling:
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
122 try:
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
123 ext = sniff.handle_uploaded_dataset_file(filename, datatypes_registry, ext=data_dict["ext"])
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
124 except Exception as e:
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
125 stop_err(str(e))
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
126 info = dict(type="dataset", dataset_id=data_dict["dataset_id"], ext=ext)
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
127
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
128 json_file.write("%s\n" % dumps(info))
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
129
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
130
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
131 if __name__ == "__main__":
fe2937ae3ee2 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/mave_tools/mavedb/ commit 13791ad3a67f107e7c5cfd925a2cbc0fb5656ab3
bgruening
parents:
diff changeset
132 __main__()