Mercurial > repos > pimarin > data_manager_bakta
comparison data_manager/bakta_build_database.py @ 15:ac4d5e1d1421 draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit b082e89a0090f9c4b2a257bb06b7c6f141b42650-dirty
author | pimarin |
---|---|
date | Wed, 02 Nov 2022 16:21:11 +0000 |
parents | bcac3aa1f494 |
children | 718080c30a76 |
comparison
equal
deleted
inserted
replaced
14:bcac3aa1f494 | 15:ac4d5e1d1421 |
---|---|
7 import tarfile | 7 import tarfile |
8 from datetime import datetime | 8 from datetime import datetime |
9 from pathlib import Path | 9 from pathlib import Path |
10 | 10 |
11 import requests | 11 import requests |
12 from alive_progress import alive_bar | |
13 | |
14 class GetBaktaDatabaseInfo: | 12 class GetBaktaDatabaseInfo: |
15 """ | 13 """ |
16 Extract bakta database information to make a json file for data_manager | 14 Extract bakta database information to make a json file for data_manager |
17 """ | 15 """ |
18 | 16 |
136 try: | 134 try: |
137 with bakta_path.open('wb') as fh_out, \ | 135 with bakta_path.open('wb') as fh_out, \ |
138 requests.get(self.db_url, stream=True) as resp: | 136 requests.get(self.db_url, stream=True) as resp: |
139 total_length = resp.headers.get('content-length') | 137 total_length = resp.headers.get('content-length') |
140 if total_length is None: # no content length header | 138 if total_length is None: # no content length header |
141 with alive_bar() as bar: | 139 for data in resp.iter_content(chunk_size=1024 * 1024): |
142 for data in resp.iter_content(chunk_size=1024 * 1024): | 140 fh_out.write(data) |
143 fh_out.write(data) | |
144 bar() | |
145 else: | 141 else: |
146 total_length = int(int(total_length) / 1024) | 142 for data in resp.iter_content(chunk_size=1024 * 1024): |
147 with alive_bar(total=total_length) as bar: | 143 fh_out.write(data) |
148 for data in resp.iter_content(chunk_size=1024 * 1024): | |
149 fh_out.write(data) | |
150 bar(incr=len(data) / 1024) | |
151 print(f'Download bakta database {self.db_version}') | 144 print(f'Download bakta database {self.db_version}') |
152 self.tarball_path = bakta_path | 145 self.tarball_path = bakta_path |
153 except IOError: | 146 except IOError: |
154 print(f'ERROR: Could not download file from Zenodo!' | 147 print(f'ERROR: Could not download file from Zenodo!' |
155 f' url={self.db_url}, path={self.tarball_name}') | 148 f' url={self.db_url}, path={self.tarball_name}') |