| 229 | |
| 230 | |
| 231 | def share_install_log( |
| 232 | paste_url: str, |
| 233 | max_bytes: int | None = None, |
| 234 | ) -> str | None: |
| 235 | log_path = logger.path |
| 236 | |
| 237 | if not log_path.exists(): |
| 238 | info(f'Log file not found: {log_path}') |
| 239 | return None |
| 240 | |
| 241 | content = logger.get_content(max_bytes=max_bytes) |
| 242 | |
| 243 | if len(content) == 0: |
| 244 | info(f'Log file is empty: {log_path}') |
| 245 | return None |
| 246 | |
| 247 | try: |
| 248 | req = urllib.request.Request(paste_url, data=content) |
| 249 | with urllib.request.urlopen(req) as response: |
| 250 | url = response.read().decode().strip() |
| 251 | except urllib.error.URLError as e: |
| 252 | info(f'Upload failed: {e}') |
| 253 | return None |
| 254 | |
| 255 | if not url.startswith('http'): |
| 256 | info(f'Unexpected response from {paste_url}: {url[:200]!r}') |
| 257 | return None |
| 258 | |
| 259 | return url |