amprolla is an apt repository merger originally intended for use with the Devuan infrastructure. This version is the third iteration of the software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
821 B

6 years ago
# see LICENSE file for copyright and license details
"""
Network functions/helpers
"""
import os
import requests
6 years ago
from .log import die, warn
6 years ago
def download(uris):
"""
Downloads a file by providing it an url and a write path in a tuple
"""
url = uris[0]
path = uris[1]
print("downloading: %s\nto: %s" % (url, path))
6 years ago
r = requests.get(url, stream=True)
6 years ago
if r.status_code == 404:
warn("download of %s failed: not found!" % url)
6 years ago
return
elif r.status_code != 200:
die("download of %s failed" % url)
6 years ago
os.makedirs(os.path.dirname(path), exist_ok=True)
f = open(path, 'wb')
# chunk_size {sh,c}ould be more on gbit servers
for chunk in r.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
# f.flush()
f.close()