from urllib import request from os import environ import sys import math import tarfile def print_progress_bar(percent_progress=0, char_size=50, clear_line=True): bar_progress = math.floor(char_size*(percent_progress/100)) bar = "=" * bar_progress + " " * (char_size - bar_progress) if clear_line: sys.stdout.write(u"\u001b[1000D") sys.stdout.write("[{:s}] {:d}%".format(bar, int(percent_progress))) sys.stdout.flush() def download_file(file_url, dest_path, bulk_size = 8192): req = request.urlopen(file_url) meta = req.info() file_size = int(meta.get('Content-Length')) with open(dest_path, 'wb') as dest_file: print('Downloading "{:s}". Size: {:d}b'.format(file_url, file_size)) downloaded_size = 0 while True: buff = req.read(bulk_size) if not buff: break downloaded_size += len(buff) dest_file.write(buff) progress = downloaded_size/file_size*100 print_progress_bar(progress) dest_file.close() # Add linebreak print("") def extract_tar(file_path, dest_dir = "."): print('Extracting "{:s}" to "{:s}"'.format(file_path, dest_dir)) with tarfile.open(file_path) as tar: tar.extractall(dest_dir) tar.close() def download_rkt(): url = "https://github.com/coreos/rkt/releases/download/v1.22.0/rkt-v1.22.0.tar.gz" file_path="rkt.tar.gz" download_file(file_url=url, dest_path=file_path) extract_tar(file_path) def download_acbuild(): url = "https://github.com/containers/build/releases/download/v0.4.0/acbuild-v0.4.0.tar.gz" file_path="acbuild.tar.gz" download_file(file_url=url, dest_path=file_path) extract_tar(file_path) if __name__ == "__main__": download_rkt() download_acbuild()