Mercurial > repos > ecology > aquainfra_importer
annotate data_source.py @ 0:cc18c3bf2666 draft default tip
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
author | ecology |
---|---|
date | Tue, 14 May 2024 20:10:29 +0000 |
parents | |
children |
rev | line source |
---|---|
0
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
1 #!/usr/bin/env python |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
2 # Retrieves data from external data source applications and |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
3 # stores in a dataset file. |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
4 # |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
5 # Data source application parameters are temporarily stored |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
6 # in the dataset file. |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
7 import json |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
8 import os |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
9 import sys |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
10 from urllib.parse import urlencode, urlparse |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
11 from urllib.request import urlopen |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
12 |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
13 from galaxy.datatypes import sniff |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
14 from galaxy.datatypes.registry import Registry |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
15 from galaxy.util import ( |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
16 DEFAULT_SOCKET_TIMEOUT, |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
17 get_charset_from_http_headers, |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
18 stream_to_open_named_file, |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
19 ) |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
20 |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
21 GALAXY_PARAM_PREFIX = "GALAXY" |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
22 GALAXY_ROOT_DIR = os.path.realpath( |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
23 os.path.join(os.path.dirname(__file__), os.pardir, os.pardir) |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
24 ) |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
25 GALAXY_DATATYPES_CONF_FILE = os.path.join( |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
26 GALAXY_ROOT_DIR, "datatypes_conf.xml" |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
27 ) |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
28 |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
29 |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
30 def main(): |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
31 if len(sys.argv) >= 3: |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
32 max_file_size = int(sys.argv[2]) |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
33 else: |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
34 max_file_size = 0 |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
35 |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
36 with open(sys.argv[1]) as fh: |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
37 params = json.load(fh) |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
38 |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
39 out_data_name = params["output_data"][0]["out_data_name"] |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
40 |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
41 URL = params["param_dict"].get("URL", None) |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
42 URL_method = params["param_dict"].get("URL_method", "get") |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
43 |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
44 datatypes_registry = Registry() |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
45 datatypes_registry.load_datatypes( |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
46 root_dir=params["job_config"]["GALAXY_ROOT_DIR"], |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
47 config=params["job_config"]["GALAXY_DATATYPES_CONF_FILE"], |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
48 ) |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
49 |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
50 for data_dict in params["output_data"]: |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
51 cur_filename = data_dict["file_name"] |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
52 cur_URL = params["param_dict"].get( |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
53 "%s|%s|URL" % (GALAXY_PARAM_PREFIX, |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
54 data_dict["out_data_name"]), URL |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
55 ) |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
56 if not cur_URL or urlparse(cur_URL).scheme not in ("http", "https", |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
57 "ftp"): |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
58 open(cur_filename, "w").write("") |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
59 sys.exit( |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
60 "The remote data source application has not sent " |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
61 "back a URL parameter in the request." |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
62 ) |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
63 |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
64 try: |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
65 if URL_method == "get": |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
66 page = urlopen(cur_URL, timeout=DEFAULT_SOCKET_TIMEOUT) |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
67 elif URL_method == "post": |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
68 param_dict = params["param_dict"] |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
69 page = urlopen( |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
70 cur_URL, |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
71 urlencode(param_dict["incoming_request_params"]).encode( |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
72 "utf-8" |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
73 ), |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
74 timeout=DEFAULT_SOCKET_TIMEOUT, |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
75 ) |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
76 except Exception as e: |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
77 sys.exit( |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
78 "The remote data source application may " |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
79 "be off line, please try again later. Error: %s" |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
80 % str(e) |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
81 ) |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
82 if max_file_size: |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
83 file_size = int(page.info().get("Content-Length", 0)) |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
84 if file_size > max_file_size: |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
85 sys.exit( |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
86 "The requested data size (%d bytes) exceeds the maximum" |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
87 "allowed size (%d bytes) on this server." |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
88 % (file_size, max_file_size) |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
89 ) |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
90 try: |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
91 cur_filename = stream_to_open_named_file( |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
92 page, |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
93 os.open( |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
94 cur_filename, |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
95 os.O_WRONLY | os.O_TRUNC | os.O_CREAT |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
96 ), |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
97 cur_filename, |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
98 source_encoding=get_charset_from_http_headers(page.headers), |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
99 ) |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
100 except Exception as e: |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
101 sys.exit("Unable to fetch %s:\n%s" % (cur_URL, e)) |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
102 |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
103 try: |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
104 ext = sniff.handle_uploaded_dataset_file( |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
105 cur_filename, datatypes_registry, ext=data_dict["ext"] |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
106 ) |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
107 except Exception as e: |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
108 sys.exit(str(e)) |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
109 |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
110 tool_provided_metadata = {out_data_name: {"ext": ext}} |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
111 |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
112 with open( |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
113 params["job_config"]["TOOL_PROVIDED_JOB_METADATA_FILE"], "w" |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
114 ) as json_file: |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
115 json.dump(tool_provided_metadata, json_file) |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
116 |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
117 |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
118 if __name__ == "__main__": |
cc18c3bf2666
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/aquainfra_importer commit 2b586af4c987b6105356736f875d2517b25a8be6
ecology
parents:
diff
changeset
|
119 main() |