|
10 | 10 | import subprocess |
11 | 11 | import sys |
12 | 12 | import time |
13 | | -import urllib.error |
14 | | -import urllib.parse |
15 | 13 | from collections.abc import Callable, Iterator |
16 | 14 | from datetime import date, datetime |
17 | 15 | from enum import Enum |
18 | 16 | from pathlib import Path |
19 | 17 | from select import EPOLLHUP, EPOLLIN, epoll |
20 | 18 | from shutil import which |
21 | 19 | from typing import TYPE_CHECKING, Any, override |
22 | | -from urllib.request import Request, urlopen |
23 | 20 |
|
24 | 21 | from .exceptions import RequirementError, SysCallError |
25 | 22 | from .output import debug, error, info |
@@ -496,45 +493,6 @@ def run_custom_user_commands(commands: list[str], installation: Installer) -> No |
496 | 493 | os.unlink(chroot_path) |
497 | 494 |
|
498 | 495 |
|
499 | | -def json_stream_to_structure(configuration_identifier: str, stream: str, target: dict[str, Any]) -> bool: |
500 | | - """ |
501 | | - Load a JSON encoded dictionary from a stream and merge it into an existing dictionary. |
502 | | - A stream can be a filepath, a URL or a raw JSON string. |
503 | | - Returns True if the operation succeeded, False otherwise. |
504 | | - +configuration_identifier is just a parameter to get meaningful, but not so long messages |
505 | | - """ |
506 | | - |
507 | | - raw: str | None = None |
508 | | - # Try using the stream as a URL that should be grabbed |
509 | | - if urllib.parse.urlparse(stream).scheme: |
510 | | - try: |
511 | | - with urlopen(Request(stream, headers={'User-Agent': 'ArchInstall'})) as response: |
512 | | - raw = response.read() |
513 | | - except urllib.error.HTTPError as err: |
514 | | - error(f"Could not fetch JSON from {stream} as {configuration_identifier}: {err}") |
515 | | - return False |
516 | | - |
517 | | - # Try using the stream as a filepath that should be read |
518 | | - if raw is None and (path := Path(stream)).exists(): |
519 | | - try: |
520 | | - raw = path.read_text() |
521 | | - except Exception as err: |
522 | | - error(f"Could not read file {stream} as {configuration_identifier}: {err}") |
523 | | - return False |
524 | | - |
525 | | - try: |
526 | | - # We use `or` to try the stream as raw JSON to be parsed |
527 | | - structure = json.loads(raw or stream) |
528 | | - except Exception as err: |
529 | | - error(f"{configuration_identifier} contains an invalid JSON format: {err}") |
530 | | - return False |
531 | | - if not isinstance(structure, dict): |
532 | | - error(f"{stream} passed as {configuration_identifier} is not a JSON encoded dictionary") |
533 | | - return False |
534 | | - target.update(structure) |
535 | | - return True |
536 | | - |
537 | | - |
538 | 496 | def secret(x: str) -> str: |
539 | 497 | """ return * with len equal to to the input string """ |
540 | 498 | return '*' * len(x) |
0 commit comments