annotate fetch_latest_pangolearn.py @ 1:f557122d379e draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
author iuc
date Sun, 25 Apr 2021 20:17:07 +0000
parents
children 437e28791761
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
1 #!/usr/bin/env python
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
2
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
3 import json
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
4 import os
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
5 import tarfile
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
6
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
7 # rely on the fact that pangolin itself uses the requests module
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
8 import requests
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
9
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
10 response = requests.get(
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
11 "https://api.github.com/repos/cov-lineages/pangoLEARN/releases/latest"
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
12 )
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
13 if response.status_code == 200:
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
14 details = json.loads(response.text)
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
15 response = requests.get(details["tarball_url"])
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
16 if response.status_code == 200:
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
17 with open("pangolearn.tgz", "wb") as handle:
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
18 handle.write(response.content)
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
19 tf = tarfile.open("pangolearn.tgz")
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
20 pl_path = tf.next().name
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
21 tf.extractall()
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
22 tf.close()
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
23 os.rename(os.path.join(pl_path, "pangoLEARN"), "datadir")
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
24 else:
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
25 response.raise_for_status()
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
26 else:
f557122d379e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit 1522bdb834ffab157d1ca25e6e74db21f62e3aae"
iuc
parents:
diff changeset
27 response.raise_for_status()