()
| 121 | |
| 122 | |
| 123 | def main() -> None: |
| 124 | parser = argparse.ArgumentParser() |
| 125 | parser.add_argument("tool", help="Tool name") |
| 126 | parser.add_argument("output", type=Path, help="output file path") |
| 127 | parser.add_argument("--tag", help="GitHub tag", required=True) |
| 128 | args = parser.parse_args() |
| 129 | |
| 130 | url = TOOLS[args.tool](args.tag) |
| 131 | output = Path(args.output) |
| 132 | |
| 133 | print(f"Downloading {url} to {output}") |
| 134 | req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"}) |
| 135 | try: |
| 136 | with urllib.request.urlopen(req) as response: |
| 137 | download(url, response, output) |
| 138 | except urllib.error.URLError as e: |
| 139 | if str(e).find("CERTIFICATE_VERIFY_FAILED") == -1: |
| 140 | raise e |
| 141 | try: |
| 142 | import certifi |
| 143 | import ssl |
| 144 | except ImportError: |
| 145 | print( |
| 146 | '"certifi" module not found. Please install it using "python -m pip install certifi".' |
| 147 | ) |
| 148 | return |
| 149 | |
| 150 | with urllib.request.urlopen( |
| 151 | req, context=ssl.create_default_context(cafile=certifi.where()) |
| 152 | ) as response: |
| 153 | download(url, response, output) |
| 154 | |
| 155 | |
| 156 | if __name__ == "__main__": |
no test coverage detected