Files
Kybus/src/main.py
2023-02-08 21:33:33 -05:00

38 lines
1.1 KiB
Python

#!/usr/bin/python3
import os
import requests
from clint.textui import progress
def downloadArtifact(artifactURL: str, downloadPath: str):
print("holding")
def downloadImage(imageURL: str):
createDownloadFolder()
# Obtain last segment of URL for file name
fileName = imageURL.split("/")[-1]
if not os.path.exists("download/" + fileName):
print("Downloading - {}".format(imageURL))
r = requests.get(imageURL, stream=True)
with open("download/" + fileName, "wb") as fd:
totalLength = int(r.headers.get('content-length'))
for ch in progress.bar(r.iter_content(chunk_size = 2048), expected_size=(totalLength/2048)):
if ch:
fd.write(ch)
fd.close()
return
def createDownloadFolder():
if not os.path.isdir("download"):
os.mkdir("download")
return
downloadImage("http://file.pinfosec.dev/files/vm-images/CentOS-7-x86_64-GenericCloud.qcow2")
downloadImage("http://file.pinfosec.dev/files/vm-images/jammy-server-cloudimg-amd64.img")
downloadImage("http://file.pinfosec.dev/files/vm-images/ubuntu-20.04-server-cloudimg-amd64.img")