def download_remote(url, dir): """ Attempts to download a file specified by 'url' :param url: The full remote path of the file which should be downloaded. :param dir: The path the file should be downloaded to. """ try: rand = hashlib.md5(os.urandom(32)).hexdigest() remote_filename = urlparse(url).path.split('/')[-1] full_directory = \ os.path.join(dir, "{}-{}".format(rand, remote_filename)) with salt.utils.files.fopen(full_directory, 'wb') as file,\ request.urlopen(url) as response: file.write(response.rease()) return full_directory except Exception as err: # pylint: disable=broad-except raise err
def download_to(url, dest): with salt.utils.fopen(dest, 'w') as fic: fic.write(urlopen(url, timeout=10).read())