| 21 | return "Other" |
| 22 | |
| 23 | def download_file(url, output_filename): |
| 24 | total_downloaded = 0 |
| 25 | total_truncated = 0 # only print download progress every 2MB to avoid spamming logs |
| 26 | |
| 27 | def report_progress(block_num, block_size, total_size): |
| 28 | nonlocal total_downloaded |
| 29 | nonlocal total_truncated |
| 30 | total_downloaded += block_size |
| 31 | if total_downloaded // (1024 * 1024) > total_truncated: |
| 32 | total_truncated = total_downloaded // (1024 * 1024) |
| 33 | if total_truncated % 2 == 0: |
| 34 | print(f"\rDownloaded {total_downloaded // (1024 * 1024)} MB", end="") |
| 35 | |
| 36 | try: |
| 37 | ssl._create_default_https_context = ssl._create_stdlib_context |
| 38 | urllib.request.urlretrieve(url, output_filename, reporthook=report_progress) |
| 39 | print(f"\nDownloaded {output_filename}") |
| 40 | return True |
| 41 | except Exception as e: |
| 42 | print(f"\nFailed to download {output_filename}") |
| 43 | print(f"Error: {str(e)}") |
| 44 | sys.exit(1) |
| 45 | |
| 46 | def check_os(os_name): |
| 47 | print("\nChecking System") |