Created
August 17, 2017 07:40
-
-
Save rgarrigue/af6e800698fc545527177673f2ad22db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def download_war(baseurl, login, password, war, version): | |
""" | |
Download a war from Nexus and return it's path | |
""" | |
try: | |
url = baseurl + "/" + war + "/" + version + "/" + war + "-" + version + ".war" | |
result = "/tmp/ " + war + "-" + version + ".war" | |
# Download file | |
# stream=True, total_size and with open just so a progress bar can be displayed with tqdm | |
r = requests.get(url, auth=(login,password), stream=True) | |
total_size = int(r.headers.get('content-length', 0)) | |
with open(result, 'wb') as f: | |
for data in tqdm(r.iter_content(1024*1024), total=total_size, unit='B', unit_scale=True): | |
f.write(data) | |
# Exception if return code above 400 | |
r.raise_for_status() | |
logging.debug(r, sort_keys=True) | |
return result | |
except Exception as e: | |
print("Exception while downloading '" + url + "' : " + str(e)) | |
exit(100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment