diff options
author | Devaev Maxim <[email protected]> | 2020-09-30 06:36:00 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2020-09-30 06:36:00 +0300 |
commit | 3f9c32e9fc518bf7e94a2507bd2e388de3f6f749 (patch) | |
tree | 92921d88e41b08aa3f29ddbb233f5a4bfc3367a7 | |
parent | 771640a79c437ecc39296faee1c4dedb016d71a2 (diff) |
moved otg devices configs to their own section
-rw-r--r-- | kvmd/apps/__init__.py | 68 | ||||
-rw-r--r-- | kvmd/apps/otg/__init__.py | 26 | ||||
-rw-r--r-- | testenv/linters/pylint.ini | 1 |
3 files changed, 56 insertions, 39 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py index a760d188..2473fa72 100644 --- a/kvmd/apps/__init__.py +++ b/kvmd/apps/__init__.py @@ -144,6 +144,7 @@ def _init_config(config_path: str, override_options: List[str], **load_flags: bo try: tools.merge(raw_config, (raw_config.pop("override", {}) or {})) tools.merge(raw_config, build_raw_from_options(override_options)) + _patch_raw(raw_config) config = make_config(raw_config, scheme) if _patch_dynamic(raw_config, config, scheme, **load_flags): @@ -154,6 +155,19 @@ def _init_config(config_path: str, override_options: List[str], **load_flags: bo raise SystemExit(f"Config error: {err}") +def _patch_raw(raw_config: Dict) -> None: + if isinstance(raw_config.get("otg"), dict): + for (old, new) in [ + ("msd", "msd"), + ("acm", "serial"), + ("drives", "drives"), + ]: + if old in raw_config["otg"]: + if not isinstance(raw_config["otg"].get("devices"), dict): + raw_config["otg"]["devices"] = {} + raw_config["otg"]["devices"][new] = raw_config["otg"].pop(old) + + def _patch_dynamic( # pylint: disable=too-many-locals raw_config: Dict, config: Section, @@ -372,36 +386,38 @@ def _get_config_scheme() -> Dict: "udc": Option("", type=valid_stripped_string), "init_delay": Option(3.0, type=valid_float_f01), - "msd": { - "user": Option("kvmd", type=valid_user), - "default": { - "stall": Option(False, type=valid_bool), - "cdrom": Option(True, type=valid_bool), - "rw": Option(False, type=valid_bool), - "removable": Option(True, type=valid_bool), - "fua": Option(True, type=valid_bool), + "devices": { + "msd": { + "user": Option("kvmd", type=valid_user), + "default": { + "stall": Option(False, type=valid_bool), + "cdrom": Option(True, type=valid_bool), + "rw": Option(False, type=valid_bool), + "removable": Option(True, type=valid_bool), + "fua": Option(True, type=valid_bool), + }, }, - }, - "acm": { - "enabled": Option(False, type=valid_bool), - }, + "serial": { + "enabled": Option(False, type=valid_bool), + }, - "ethernet": { - "enabled": Option(False, type=valid_bool), - "host_mac": Option("", type=valid_mac, only_if="enabled"), - "kvm_mac": Option("", type=valid_mac, only_if="enabled"), - }, + "ethernet": { + "enabled": Option(False, type=valid_bool), + "host_mac": Option("", type=valid_mac, only_if="enabled"), + "kvm_mac": Option("", type=valid_mac, only_if="enabled"), + }, - "drives": { - "enabled": Option(False, type=valid_bool), - "count": Option(1, type=valid_int_f1), - "default": { - "stall": Option(False, type=valid_bool), - "cdrom": Option(False, type=valid_bool), - "rw": Option(True, type=valid_bool), - "removable": Option(True, type=valid_bool), - "fua": Option(True, type=valid_bool), + "drives": { + "enabled": Option(False, type=valid_bool), + "count": Option(1, type=valid_int_f1), + "default": { + "stall": Option(False, type=valid_bool), + "cdrom": Option(False, type=valid_bool), + "rw": Option(True, type=valid_bool), + "removable": Option(True, type=valid_bool), + "fua": Option(True, type=valid_bool), + }, }, }, }, diff --git a/kvmd/apps/otg/__init__.py b/kvmd/apps/otg/__init__.py index 2085134b..85db4b9d 100644 --- a/kvmd/apps/otg/__init__.py +++ b/kvmd/apps/otg/__init__.py @@ -96,8 +96,8 @@ def _find_udc(udc: str) -> str: def _check_config(config: Section) -> None: if ( - not config.otg.acm.enabled - and not config.otg.ethernet.enabled + not config.otg.devices.serial.enabled + and not config.otg.devices.ethernet.enabled and config.kvmd.hid.type != "otg" and config.kvmd.msd.type != "otg" ): @@ -105,7 +105,7 @@ def _check_config(config: Section) -> None: # ===== -def _create_acm(gadget_path: str, config_path: str) -> None: +def _create_serial(gadget_path: str, config_path: str) -> None: func_path = join(gadget_path, "functions/acm.usb0") _mkdir(func_path) _symlink(func_path, join(config_path, "acm.usb0")) @@ -188,13 +188,13 @@ def _cmd_start(config: Section) -> None: _write(join(config_path, "strings/0x409/configuration"), "Config 1: ECM network") _write(join(config_path, "MaxPower"), "250") - if config.otg.acm.enabled: - logger.info("Required ACM") - _create_acm(gadget_path, config_path) + if config.otg.devices.serial.enabled: + logger.info("Required Serial") + _create_serial(gadget_path, config_path) - if config.otg.ethernet.enabled: + if config.otg.devices.ethernet.enabled: logger.info("Required Ethernet") - _create_ethernet(gadget_path, config_path, config.otg.ethernet.host_mac, config.otg.ethernet.kvm_mac) + _create_ethernet(gadget_path, config_path, **config.otg.devices.ethernet._unpack(ignore=["enabled"])) if config.kvmd.hid.type == "otg": logger.info("Required HID") @@ -203,11 +203,11 @@ def _cmd_start(config: Section) -> None: if config.kvmd.msd.type == "otg": logger.info("Required MSD") - _create_msd(gadget_path, config_path, 0, config.otg.msd.user, **config.otg.msd.default._unpack()) # pylint: disable=protected-access - if config.otg.drives.enabled: - logger.info("Required MSD extra drives: %d", config.otg.drives.count) - for instance in range(config.otg.drives.count): - _create_msd(gadget_path, config_path, instance + 1, "root", **config.otg.drives.default._unpack()) # pylint: disable=protected-access + _create_msd(gadget_path, config_path, 0, config.otg.devices.msd.user, **config.otg.devices.msd.default._unpack()) + if config.otg.devices.drives.enabled: + logger.info("Required MSD extra drives: %d", config.otg.devices.drives.count) + for instance in range(config.otg.devices.drives.count): + _create_msd(gadget_path, config_path, instance + 1, "root", **config.otg.devices.drives.default._unpack()) logger.info("Enabling the gadget ...") _write(join(gadget_path, "UDC"), udc) diff --git a/testenv/linters/pylint.ini b/testenv/linters/pylint.ini index a07b9221..2d0f3de8 100644 --- a/testenv/linters/pylint.ini +++ b/testenv/linters/pylint.ini @@ -33,6 +33,7 @@ disable = no-else-return, len-as-condition, raise-missing-from, + protected-access, [REPORTS] msg-template = {symbol} -- {path}:{line}({obj}): {msg} |