Mercurial > repos > blankenberglab > data_manager_refgenie_pull
comparison data_manager/data_manager_refgenie_pull.py @ 3:b2fa406276e7 draft default tip
"planemo upload for repository https://github.com/blankenberglab/galaxy-tools-blankenberg/tree/main/data_managers/data_manager_refgenie_pull commit 793d970b919fcfd5f21a2d6e03e825b05dd56b69"
author | blankenberglab |
---|---|
date | Fri, 01 Apr 2022 16:14:13 +0000 |
parents | 2cb1863cd236 |
children |
comparison
equal
deleted
inserted
replaced
2:2cb1863cd236 | 3:b2fa406276e7 |
---|---|
2 | 2 |
3 | 3 |
4 import argparse | 4 import argparse |
5 import logging | 5 import logging |
6 from base64 import urlsafe_b64encode | 6 from base64 import urlsafe_b64encode |
7 from html import escape | |
7 from urllib.parse import urljoin | 8 from urllib.parse import urljoin |
8 | 9 |
9 import refgenconf | 10 import refgenconf |
10 import requests | 11 import requests |
11 | 12 |
13 log = logging.getLogger("tools.iuc.data_managers.data_manager_refgenie_pull") | 14 log = logging.getLogger("tools.iuc.data_managers.data_manager_refgenie_pull") |
14 | 15 |
15 | 16 |
16 def galaxy_code_get_refgenie_assets(refgenie_config_file): | 17 def galaxy_code_get_refgenie_assets(refgenie_config_file): |
17 try: | 18 try: |
19 rval = [] | |
18 rgc = refgenconf.RefGenConf(refgenie_config_file, writable=False, skip_read_lock=True) | 20 rgc = refgenconf.RefGenConf(refgenie_config_file, writable=False, skip_read_lock=True) |
19 except refgenconf.exceptions.RefgenconfError as e: | 21 for urlname, genomes in rgc.listr().items(): |
20 return[{'name': str(e), 'value': 'ERROR', 'options': [], 'selected': False}] | 22 urlname_64 = urlsafe_b64encode(bytes(urlname, 'utf8')).decode('utf8') |
21 rval = [] | 23 ul = [] |
22 for urlname, genomes in rgc.listr().items(): | 24 for genome, assets in genomes.items(): |
23 urlname_64 = urlsafe_b64encode(bytes(urlname, 'utf8')).decode('utf8') | 25 al = [] |
24 ul = [] | 26 for name in assets: |
25 for genome, assets in genomes.items(): | 27 al.append({'name': name, 'value': '%s/%s/%s' % (urlname_64, genome, name), 'options': [], 'selected': False}) |
26 al = [] | 28 ul.append({'name': genome, 'value': genome, 'options': al, 'selected': False}) |
27 for name in assets: | 29 rval.append({'name': urlname, 'value': urlname_64, 'options': ul, 'selected': False}) |
28 al.append({'name': name, 'value': '%s/%s/%s' % (urlname_64, genome, name), 'options': [], 'selected': False}) | 30 return rval |
29 ul.append({'name': genome, 'value': genome, 'options': al, 'selected': False}) | 31 except Exception as e: |
30 rval.append({'name': urlname, 'value': urlname_64, 'options': ul, 'selected': False}) | 32 log.debug("Failed to access refgenie server: %s", e) |
31 return rval | 33 return[{'name': escape(str(e)), 'value': 'ERROR', 'options': [], 'selected': False}] |
32 | 34 |
33 | 35 |
34 if __name__ == '__main__': | 36 if __name__ == '__main__': |
35 parser = argparse.ArgumentParser() | 37 parser = argparse.ArgumentParser() |
36 parser.add_argument('-n', '--names', dest='names', action='store', default=None, help='Table names to reload') | 38 parser.add_argument('-n', '--names', dest='names', action='store', default=None, help='Table names to reload') |
37 parser.add_argument('-u', '--url', dest='url', action='store', default=None, help='Base url for reload') | 39 parser.add_argument('-u', '--url', dest='url', action='store', default=None, help='Base url for reload') |
38 parser.add_argument('-k', '--key', dest='key', action='store', default=None, help='Galaxy API Key') | 40 parser.add_argument('-k', '--key', dest='key', action='store', default=None, help='Galaxy API Key') |
41 parser.add_argument('-g', '--graceful', dest='graceful', action='store_true', help='Fail gracefully') | |
39 | 42 |
40 args = parser.parse_args() | 43 args = parser.parse_args() |
41 if not args.names: | 44 try: |
42 tables = requests.get(urljoin(args.url, "api/tool_data"), params={'key': args.key}).json() | 45 if not args.names: |
43 args.names = [d.get('name') for d in tables] | 46 tables = requests.get(urljoin(args.url, "api/tool_data"), params={'key': args.key}).json() |
44 for name in args.names: | 47 args.names = [d.get('name') for d in tables] |
45 print(requests.get(urljoin(args.url, "api/tool_data/%s/reload" % (name)), params={'key': args.key}).json()) | 48 for name in args.names: |
49 print(requests.get(urljoin(args.url, "api/tool_data/%s/reload" % (name)), params={'key': args.key}).json()) | |
50 except Exception as e: | |
51 if args.graceful: | |
52 print("Failed to reload data tables:\n%s" % (e)) | |
53 else: | |
54 raise e |