Skip to content

Commit 22a4b2f

Browse files
committed
Fix ftp download in download_tarball.py
1 parent c731619 commit 22a4b2f

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

snakefile_scripts/download_tarball.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22
import requests
3-
import tempfile
43
import tarfile
4+
import sys
55
import urllib.request as urlrequest
66
from snakemake.logging import logger
77

@@ -19,14 +19,17 @@ def download_tarball(dl_url):
1919
f"Downloading database archive from ftp server at "
2020
f"{dl_url} to temp file...")
2121

22-
temp_dl_file = tempfile.TemporaryFile()
22+
try:
23+
dl_resp = urlrequest.urlopen(dl_url)
2324

24-
urlrequest.urlretrieve(
25-
dl_url, temp_dl_file)
25+
except Exception as e:
26+
logger.error(e)
27+
sys.exit(1)
2628

27-
tar_out = tarfile.open(temp_dl_file)
29+
tar_out = tarfile.open(fileobj = dl_resp, mode="r:gz")
2830

2931
elif re.match("http[s]?://*", dl_url) or not re.match("[a-z]*://", dl_url):
32+
# FIXME Change http download to also use urllib.request for consistency.
3033
if not re.match("[a-z]*://", dl_url):
3134
logger.info(
3235
f"No protocol identifier in {dl_url}, assuming http/https...")

0 commit comments

Comments
 (0)