annotate baric_archive.py @ 0:5c689d1e41fe draft default tip

"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
author genouest
date Fri, 04 Mar 2022 11:16:56 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
1 #!/usr/bin/env python
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
2 # Retrieves data from external data source applications and stores in a dataset file.
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
3 # Data source application parameters are temporarily stored in the dataset file.
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
4 import os
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
5 import socket
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
6 import sys
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
7 import urllib
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
8 from json import dumps, loads
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
9 from urllib.parse import urlparse
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
10 from urllib.request import urlopen
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
11
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
12 from galaxy.datatypes import sniff
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
13 from galaxy.datatypes.registry import Registry
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
14 from galaxy.jobs import TOOL_PROVIDED_JOB_METADATA_FILE
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
15 from galaxy.util import get_charset_from_http_headers
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
16
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
17 GALAXY_PARAM_PREFIX = 'GALAXY'
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
18 GALAXY_ROOT_DIR = os.path.realpath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
19 GALAXY_DATATYPES_CONF_FILE = os.path.join(GALAXY_ROOT_DIR, 'datatypes_conf.xml')
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
20
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
21
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
22 def stop_err(msg, json_file=None):
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
23 sys.stderr.write(msg)
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
24 # Need to write valid (but empty) json to avoid metadata collection failure
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
25 # leading to "unable to finish job" error with no logs
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
26 if json_file is not None:
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
27 json_file.write("%s\n" % dumps({}))
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
28 sys.exit(1)
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
29
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
30
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
31 def load_input_parameters(filename, erase_file=True):
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
32 datasource_params = {}
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
33 try:
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
34 json_params = loads(open(filename, 'r').read())
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
35 datasource_params = json_params.get('param_dict')
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
36 except Exception:
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
37 json_params = None
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
38 for line in open(filename, 'r'):
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
39 try:
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
40 line = line.strip()
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
41 fields = line.split('\t')
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
42 datasource_params[fields[0]] = fields[1]
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
43 except Exception:
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
44 continue
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
45 if erase_file:
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
46 open(filename, 'w').close() # open file for writing, then close, removes params from file
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
47 return json_params, datasource_params
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
48
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
49
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
50 def __main__():
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
51 filename = sys.argv[1]
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
52
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
53 user_email = sys.argv[2]
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
54 user_id = sys.argv[3]
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
55
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
56 try:
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
57 max_file_size = int(sys.argv[4])
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
58 except Exception:
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
59 max_file_size = 0
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
60
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
61 job_params, params = load_input_parameters(filename)
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
62 if job_params is None: # using an older tabular file
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
63 enhanced_handling = False
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
64 job_params = dict(param_dict=params)
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
65 job_params['output_data'] = [dict(out_data_name='output',
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
66 ext='auto',
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
67 file_name=filename,
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
68 extra_files_path=None)]
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
69 job_params['job_config'] = dict(GALAXY_ROOT_DIR=GALAXY_ROOT_DIR, GALAXY_DATATYPES_CONF_FILE=GALAXY_DATATYPES_CONF_FILE, TOOL_PROVIDED_JOB_METADATA_FILE=TOOL_PROVIDED_JOB_METADATA_FILE)
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
70 else:
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
71 enhanced_handling = True
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
72 json_file = open(job_params['job_config']['TOOL_PROVIDED_JOB_METADATA_FILE'], 'w') # specially named file for output junk to pass onto set metadata
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
73
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
74 datatypes_registry = Registry()
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
75 datatypes_registry.load_datatypes(root_dir=job_params['job_config']['GALAXY_ROOT_DIR'], config=job_params['job_config']['GALAXY_DATATYPES_CONF_FILE'])
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
76
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
77 URL = params.get('URL', None) # using exactly URL indicates that only one dataset is being downloaded
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
78 export = params.get('export', None)
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
79 userkey = params.get('userkey', 'none')
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
80 URL_method = params.get('URL_method', None)
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
81
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
82 URL = URL + "&userkey=" + userkey + "&user_email=" + user_email + "&user_id=" + user_id
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
83
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
84 # The Python support for fetching resources from the web is layered. urllib uses the httplib
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
85 # library, which in turn uses the socket library. As of Python 2.3 you can specify how long
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
86 # a socket should wait for a response before timing out. By default the socket module has no
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
87 # timeout and can hang. Currently, the socket timeout is not exposed at the httplib or urllib2
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
88 # levels. However, you can set the default timeout ( in seconds ) globally for all sockets by
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
89 # doing the following.
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
90 socket.setdefaulttimeout(600)
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
91
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
92 for data_dict in job_params['output_data']:
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
93 cur_filename = data_dict.get('file_name', filename)
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
94 cur_URL = params.get('%s|%s|URL' % (GALAXY_PARAM_PREFIX, data_dict['out_data_name']), URL)
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
95 if not cur_URL or urlparse(cur_URL).scheme not in ('http', 'https', 'ftp'):
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
96 open(cur_filename, 'w').write("")
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
97 stop_err('The remote data source application has not sent back a URL parameter in the request.', json_file)
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
98
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
99 # The following calls to urlopen() will use the above default timeout
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
100 try:
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
101 if not URL_method or URL_method == 'get':
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
102 page = urlopen(cur_URL)
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
103 elif URL_method == 'post':
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
104 page = urlopen(cur_URL, urllib.parse.urlencode(params).encode("utf-8"))
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
105 except Exception as e:
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
106 stop_err('The remote data source application may be off line, please try again later. Error: %s' % str(e), json_file)
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
107 if max_file_size:
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
108 file_size = int(page.info().get('Content-Length', 0))
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
109 if file_size > max_file_size:
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
110 stop_err('The size of the data (%d bytes) you have requested exceeds the maximum allowed (%d bytes) on this server.' % (file_size, max_file_size), json_file)
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
111 # handle files available locally
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
112 if export:
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
113 try:
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
114 local_file = export + page.read()
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
115 os.remove(cur_filename)
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
116 os.symlink(local_file, cur_filename)
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
117 except Exception as e:
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
118 stop_err('Unable to symlink %s to %s:\n%s' % (local_file, cur_filename, e), json_file)
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
119 else:
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
120 try:
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
121 cur_filename = sniff.stream_to_open_named_file(page, os.open(cur_filename, os.O_WRONLY | os.O_CREAT), cur_filename, source_encoding=get_charset_from_http_headers(page.headers))
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
122 except Exception as e:
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
123 stop_err('Unable to fetch %s:\n%s' % (cur_URL, e), json_file)
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
124
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
125 # here import checks that upload tool performs
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
126 if enhanced_handling:
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
127 try:
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
128 ext = sniff.handle_uploaded_dataset_file(filename, datatypes_registry, ext=data_dict['ext'])
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
129 except Exception as e:
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
130 stop_err(str(e), json_file)
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
131 info = dict(type='dataset',
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
132 dataset_id=data_dict['dataset_id'],
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
133 ext=ext)
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
134
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
135 json_file.write("%s\n" % dumps(info))
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
136
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
137
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
138 if __name__ == "__main__":
5c689d1e41fe "planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff changeset
139 __main__()