Mercurial > repos > iuc > pangolin
comparison fetch_latest_pangolearn.py @ 6:437e28791761 draft
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit f53dc92d3cf6997da9ad21f01ad3fd3477aae068"
| author | iuc |
|---|---|
| date | Wed, 07 Jul 2021 09:24:31 +0000 |
| parents | f557122d379e |
| children |
comparison
equal
deleted
inserted
replaced
| 5:42a174224817 | 6:437e28791761 |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 import argparse | |
| 3 import json | 4 import json |
| 4 import os | 5 import os |
| 6 import sys | |
| 5 import tarfile | 7 import tarfile |
| 6 | 8 |
| 7 # rely on the fact that pangolin itself uses the requests module | 9 # rely on the fact that pangolin itself uses the requests module |
| 8 import requests | 10 import requests |
| 11 from requests.adapters import HTTPAdapter | |
| 9 | 12 |
| 10 response = requests.get( | 13 parser = argparse.ArgumentParser(description='download latest pangoLEARN database') |
| 11 "https://api.github.com/repos/cov-lineages/pangoLEARN/releases/latest" | 14 parser.add_argument('--timeout', type=float, default=60.0, help="Timeout for connecting or downloading the pangoLEARN database (in seconds)") |
| 12 ) | 15 parser.add_argument('--max_retries', type=int, default=5, help="How many times to retry fetching the pangoLEARN database") |
| 13 if response.status_code == 200: | 16 args = parser.parse_args() |
| 14 details = json.loads(response.text) | 17 |
| 15 response = requests.get(details["tarball_url"]) | 18 try: |
| 19 s = requests.Session() | |
| 20 s.mount('https://', HTTPAdapter(max_retries=args.max_retries)) | |
| 21 response = s.get( | |
| 22 "https://api.github.com/repos/cov-lineages/pangoLEARN/releases/latest" | |
| 23 ) | |
| 16 if response.status_code == 200: | 24 if response.status_code == 200: |
| 17 with open("pangolearn.tgz", "wb") as handle: | 25 details = json.loads(response.text) |
| 18 handle.write(response.content) | 26 response = s.get(details["tarball_url"], timeout=args.timeout) |
| 19 tf = tarfile.open("pangolearn.tgz") | 27 if response.status_code == 200: |
| 20 pl_path = tf.next().name | 28 with open("pangolearn.tgz", "wb") as handle: |
| 21 tf.extractall() | 29 handle.write(response.content) |
| 22 tf.close() | 30 tf = tarfile.open("pangolearn.tgz") |
| 23 os.rename(os.path.join(pl_path, "pangoLEARN"), "datadir") | 31 pl_path = tf.next().name |
| 32 tf.extractall() | |
| 33 tf.close() | |
| 34 os.rename(os.path.join(pl_path, "pangoLEARN"), "datadir") | |
| 35 else: | |
| 36 response.raise_for_status() | |
| 24 else: | 37 else: |
| 25 response.raise_for_status() | 38 response.raise_for_status() |
| 26 else: | 39 except (requests.ConnectionError, requests.HTTPError, requests.TooManyRedirects) as e: |
| 27 response.raise_for_status() | 40 sys.exit('Failed to download pangoLEARN database: {}'.format(e)) |
| 41 except requests.Timeout: | |
| 42 sys.exit('Timeout while trying to download pangoLEARN database') |
