|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# This file is part of BOINC. |
| 4 | +# https://boinc.berkeley.edu |
| 5 | +# Copyright (C) 2026 University of California |
| 6 | +# |
| 7 | +# BOINC is free software; you can redistribute it and/or modify it |
| 8 | +# under the terms of the GNU Lesser General Public License |
| 9 | +# as published by the Free Software Foundation, |
| 10 | +# either version 3 of the License, or (at your option) any later version. |
| 11 | +# |
| 12 | +# BOINC is distributed in the hope that it will be useful, |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 15 | +# See the GNU Lesser General Public License for more details. |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU Lesser General Public License |
| 18 | +# along with BOINC. If not, see <http://www.gnu.org/licenses/>. |
| 19 | + |
| 20 | +""" |
| 21 | +Download BOINC installer for Windows based on platform and version type. |
| 22 | +
|
| 23 | +Usage: |
| 24 | + python3 download_boinc_installer.py <platform> <type> |
| 25 | +
|
| 26 | + platform: x64 or arm64 |
| 27 | + type: release or alpha |
| 28 | +
|
| 29 | +Examples: |
| 30 | + python3 download_boinc_installer.py x64 release |
| 31 | + python3 download_boinc_installer.py arm64 alpha |
| 32 | +""" |
| 33 | + |
| 34 | +import sys |
| 35 | +import urllib.request |
| 36 | +import xml.etree.ElementTree as ET |
| 37 | + |
| 38 | + |
| 39 | +def download_file(url, filename): |
| 40 | + """Download a file from URL and save it with the given filename.""" |
| 41 | + print(f"Downloading {url}...") |
| 42 | + urllib.request.urlretrieve(url, filename) |
| 43 | + print(f"Successfully downloaded to {filename}") |
| 44 | + |
| 45 | + |
| 46 | +def get_download_url(xml_content, platform, version_type): |
| 47 | + """ |
| 48 | + Parse XML and extract download URL based on platform and version type. |
| 49 | +
|
| 50 | + Args: |
| 51 | + xml_content: XML content as string |
| 52 | + platform: 'x64' or 'arm64' |
| 53 | + version_type: 'release' or 'alpha' |
| 54 | +
|
| 55 | + Returns: |
| 56 | + URL string or None if not found |
| 57 | + """ |
| 58 | + root = ET.fromstring(xml_content) |
| 59 | + |
| 60 | + # Map input parameters to XML values |
| 61 | + platform_map = { |
| 62 | + 'x64': 'Windows Intel-compatible 64-bit', |
| 63 | + 'arm64': 'Windows ARM 64-bit' |
| 64 | + } |
| 65 | + |
| 66 | + version_map = { |
| 67 | + 'release': 'Recommended version', |
| 68 | + 'alpha': 'Development version' |
| 69 | + } |
| 70 | + |
| 71 | + target_platform = platform_map.get(platform) |
| 72 | + target_version = version_map.get(version_type) |
| 73 | + |
| 74 | + if not target_platform or not target_version: |
| 75 | + print(f"Error: Invalid platform '{platform}' or type '{version_type}'") |
| 76 | + return None |
| 77 | + |
| 78 | + # Find matching version entry |
| 79 | + for version in root.findall('version'): |
| 80 | + platform_elem = version.find('platform') |
| 81 | + description_elem = version.find('description') |
| 82 | + url_elem = version.find('url') |
| 83 | + |
| 84 | + if (platform_elem is not None and platform_elem.text == target_platform and |
| 85 | + description_elem is not None and description_elem.text == target_version and |
| 86 | + url_elem is not None): |
| 87 | + return url_elem.text |
| 88 | + |
| 89 | + return None |
| 90 | + |
| 91 | + |
| 92 | +def main(): |
| 93 | + if len(sys.argv) != 3: |
| 94 | + print("Usage: python3 download_boinc_installer.py <platform> <type>") |
| 95 | + print(" platform: x64 or arm64") |
| 96 | + print(" type: release or alpha") |
| 97 | + sys.exit(1) |
| 98 | + |
| 99 | + platform = sys.argv[1].lower() |
| 100 | + version_type = sys.argv[2].lower() |
| 101 | + |
| 102 | + if platform not in ['x64', 'arm64']: |
| 103 | + print(f"Error: Invalid platform '{platform}'. Use 'x64' or 'arm64'") |
| 104 | + sys.exit(1) |
| 105 | + |
| 106 | + if version_type not in ['release', 'alpha']: |
| 107 | + print(f"Error: Invalid type '{version_type}'. Use 'release' or 'alpha'") |
| 108 | + sys.exit(1) |
| 109 | + |
| 110 | + xml_url = 'https://boinc.berkeley.edu/download_all.php?xml=1' |
| 111 | + |
| 112 | + print(f"Fetching version information from {xml_url}...") |
| 113 | + try: |
| 114 | + with urllib.request.urlopen(xml_url) as response: |
| 115 | + xml_content = response.read().decode('utf-8') |
| 116 | + except Exception as e: |
| 117 | + print(f"Error downloading XML: {e}") |
| 118 | + sys.exit(1) |
| 119 | + |
| 120 | + download_url = get_download_url(xml_content, platform, version_type) |
| 121 | + |
| 122 | + if not download_url: |
| 123 | + if version_type == 'alpha': |
| 124 | + print(f"Development version for {platform} is not available. This is normal.") |
| 125 | + sys.exit(0) |
| 126 | + else: |
| 127 | + print(f"Error: Could not find download URL for {platform} {version_type}") |
| 128 | + sys.exit(1) |
| 129 | + |
| 130 | + output_filename = f"{platform}_{version_type}.exe" |
| 131 | + |
| 132 | + try: |
| 133 | + download_file(download_url, output_filename) |
| 134 | + print(f"Download completed successfully: {output_filename}") |
| 135 | + except Exception as e: |
| 136 | + print(f"Error downloading file: {e}") |
| 137 | + sys.exit(1) |
| 138 | + |
| 139 | + |
| 140 | +if __name__ == '__main__': |
| 141 | + main() |
0 commit comments