# HG changeset patch # User iuc # Date 1625649871 0 # Node ID 437e287917619d28fbe5162ad2087de0c5e084f1 # Parent 42a1742248175a7ee3f2dd7e7be236214a85c21a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit f53dc92d3cf6997da9ad21f01ad3fd3477aae068" diff -r 42a174224817 -r 437e28791761 fetch_latest_pangolearn.py --- a/fetch_latest_pangolearn.py Mon Jun 21 16:14:55 2021 +0000 +++ b/fetch_latest_pangolearn.py Wed Jul 07 09:24:31 2021 +0000 @@ -1,27 +1,42 @@ #!/usr/bin/env python +import argparse import json import os +import sys import tarfile # rely on the fact that pangolin itself uses the requests module import requests +from requests.adapters import HTTPAdapter -response = requests.get( - "https://api.github.com/repos/cov-lineages/pangoLEARN/releases/latest" -) -if response.status_code == 200: - details = json.loads(response.text) - response = requests.get(details["tarball_url"]) +parser = argparse.ArgumentParser(description='download latest pangoLEARN database') +parser.add_argument('--timeout', type=float, default=60.0, help="Timeout for connecting or downloading the pangoLEARN database (in seconds)") +parser.add_argument('--max_retries', type=int, default=5, help="How many times to retry fetching the pangoLEARN database") +args = parser.parse_args() + +try: + s = requests.Session() + s.mount('https://', HTTPAdapter(max_retries=args.max_retries)) + response = s.get( + "https://api.github.com/repos/cov-lineages/pangoLEARN/releases/latest" + ) if response.status_code == 200: - with open("pangolearn.tgz", "wb") as handle: - handle.write(response.content) - tf = tarfile.open("pangolearn.tgz") - pl_path = tf.next().name - tf.extractall() - tf.close() - os.rename(os.path.join(pl_path, "pangoLEARN"), "datadir") + details = json.loads(response.text) + response = s.get(details["tarball_url"], timeout=args.timeout) + if response.status_code == 200: + with open("pangolearn.tgz", "wb") as handle: + handle.write(response.content) + tf = tarfile.open("pangolearn.tgz") + pl_path = tf.next().name + tf.extractall() + tf.close() + os.rename(os.path.join(pl_path, "pangoLEARN"), "datadir") + else: + response.raise_for_status() else: response.raise_for_status() -else: - response.raise_for_status() +except (requests.ConnectionError, requests.HTTPError, requests.TooManyRedirects) as e: + sys.exit('Failed to download pangoLEARN database: {}'.format(e)) +except requests.Timeout: + sys.exit('Timeout while trying to download pangoLEARN database') diff -r 42a174224817 -r 437e28791761 pangolin.xml --- a/pangolin.xml Mon Jun 21 16:14:55 2021 +0000 +++ b/pangolin.xml Wed Jul 07 09:24:31 2021 +0000 @@ -1,4 +1,4 @@ - + Phylogenetic Assignment of Outbreak Lineages 3.1.4 @@ -9,7 +9,7 @@ Use default database built in to pangolin (not recommended) + + @@ -171,6 +173,17 @@ + + + + + + + + + + +