Mercurial > repos > genouest > baric_archive_toulouse
annotate baric_archive.py @ 0:1ae6b80f1e03 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:34 +0000 |
parents | |
children |
rev | line source |
---|---|
0
1ae6b80f1e03
"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 |
1ae6b80f1e03
"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. |
1ae6b80f1e03
"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. |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
4 import os |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
5 import socket |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
6 import sys |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
7 import urllib |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
11 |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
16 |
1ae6b80f1e03
"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' |
1ae6b80f1e03
"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)) |
1ae6b80f1e03
"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') |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
20 |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
21 |
1ae6b80f1e03
"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): |
1ae6b80f1e03
"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) |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"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: |
1ae6b80f1e03
"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({})) |
1ae6b80f1e03
"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) |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
29 |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
30 |
1ae6b80f1e03
"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): |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
32 datasource_params = {} |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
33 try: |
1ae6b80f1e03
"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()) |
1ae6b80f1e03
"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') |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
36 except Exception: |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"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'): |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
39 try: |
1ae6b80f1e03
"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() |
1ae6b80f1e03
"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') |
1ae6b80f1e03
"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] |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
43 except Exception: |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
44 continue |
1ae6b80f1e03
"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: |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
48 |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
49 |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
50 def __main__(): |
1ae6b80f1e03
"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] |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
52 |
1ae6b80f1e03
"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] |
1ae6b80f1e03
"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] |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
55 |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
56 try: |
1ae6b80f1e03
"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]) |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
58 except Exception: |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
60 |
1ae6b80f1e03
"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) |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"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) |
1ae6b80f1e03
"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', |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
66 ext='auto', |
1ae6b80f1e03
"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, |
1ae6b80f1e03
"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)] |
1ae6b80f1e03
"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) |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
70 else: |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
73 |
1ae6b80f1e03
"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() |
1ae6b80f1e03
"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']) |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
76 |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"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) |
1ae6b80f1e03
"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') |
1ae6b80f1e03
"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) |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
81 |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
83 |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"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. |
1ae6b80f1e03
"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) |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
91 |
1ae6b80f1e03
"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']: |
1ae6b80f1e03
"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) |
1ae6b80f1e03
"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) |
1ae6b80f1e03
"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'): |
1ae6b80f1e03
"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("") |
1ae6b80f1e03
"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) |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
98 |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
100 try: |
1ae6b80f1e03
"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': |
1ae6b80f1e03
"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) |
1ae6b80f1e03
"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': |
1ae6b80f1e03
"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")) |
1ae6b80f1e03
"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: |
1ae6b80f1e03
"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) |
1ae6b80f1e03
"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: |
1ae6b80f1e03
"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)) |
1ae6b80f1e03
"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: |
1ae6b80f1e03
"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) |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
112 if export: |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
113 try: |
1ae6b80f1e03
"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() |
1ae6b80f1e03
"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) |
1ae6b80f1e03
"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) |
1ae6b80f1e03
"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: |
1ae6b80f1e03
"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) |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
119 else: |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
120 try: |
1ae6b80f1e03
"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)) |
1ae6b80f1e03
"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: |
1ae6b80f1e03
"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) |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
124 |
1ae6b80f1e03
"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 |
1ae6b80f1e03
"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: |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
127 try: |
1ae6b80f1e03
"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']) |
1ae6b80f1e03
"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: |
1ae6b80f1e03
"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) |
1ae6b80f1e03
"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', |
1ae6b80f1e03
"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'], |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
133 ext=ext) |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
134 |
1ae6b80f1e03
"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)) |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
136 |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
137 |
1ae6b80f1e03
"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__": |
1ae6b80f1e03
"planemo upload for repository https://github.com/genouest/galaxy-tools/tree/master/tools/baric_archive commit 6419e960f00c0e1c3950bad500487d3681797b40"
genouest
parents:
diff
changeset
|
139 __main__() |