mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 09:10:30 +08:00
moved otg devices configs to their own section
This commit is contained in:
parent
771640a79c
commit
3f9c32e9fc
@ -144,6 +144,7 @@ def _init_config(config_path: str, override_options: List[str], **load_flags: bo
|
|||||||
try:
|
try:
|
||||||
tools.merge(raw_config, (raw_config.pop("override", {}) or {}))
|
tools.merge(raw_config, (raw_config.pop("override", {}) or {}))
|
||||||
tools.merge(raw_config, build_raw_from_options(override_options))
|
tools.merge(raw_config, build_raw_from_options(override_options))
|
||||||
|
_patch_raw(raw_config)
|
||||||
config = make_config(raw_config, scheme)
|
config = make_config(raw_config, scheme)
|
||||||
|
|
||||||
if _patch_dynamic(raw_config, config, scheme, **load_flags):
|
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}")
|
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
|
def _patch_dynamic( # pylint: disable=too-many-locals
|
||||||
raw_config: Dict,
|
raw_config: Dict,
|
||||||
config: Section,
|
config: Section,
|
||||||
@ -372,36 +386,38 @@ def _get_config_scheme() -> Dict:
|
|||||||
"udc": Option("", type=valid_stripped_string),
|
"udc": Option("", type=valid_stripped_string),
|
||||||
"init_delay": Option(3.0, type=valid_float_f01),
|
"init_delay": Option(3.0, type=valid_float_f01),
|
||||||
|
|
||||||
"msd": {
|
"devices": {
|
||||||
"user": Option("kvmd", type=valid_user),
|
"msd": {
|
||||||
"default": {
|
"user": Option("kvmd", type=valid_user),
|
||||||
"stall": Option(False, type=valid_bool),
|
"default": {
|
||||||
"cdrom": Option(True, type=valid_bool),
|
"stall": Option(False, type=valid_bool),
|
||||||
"rw": Option(False, type=valid_bool),
|
"cdrom": Option(True, type=valid_bool),
|
||||||
"removable": Option(True, type=valid_bool),
|
"rw": Option(False, type=valid_bool),
|
||||||
"fua": Option(True, type=valid_bool),
|
"removable": Option(True, type=valid_bool),
|
||||||
|
"fua": Option(True, type=valid_bool),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
|
|
||||||
"acm": {
|
"serial": {
|
||||||
"enabled": Option(False, type=valid_bool),
|
"enabled": Option(False, type=valid_bool),
|
||||||
},
|
},
|
||||||
|
|
||||||
"ethernet": {
|
"ethernet": {
|
||||||
"enabled": Option(False, type=valid_bool),
|
"enabled": Option(False, type=valid_bool),
|
||||||
"host_mac": Option("", type=valid_mac, only_if="enabled"),
|
"host_mac": Option("", type=valid_mac, only_if="enabled"),
|
||||||
"kvm_mac": Option("", type=valid_mac, only_if="enabled"),
|
"kvm_mac": Option("", type=valid_mac, only_if="enabled"),
|
||||||
},
|
},
|
||||||
|
|
||||||
"drives": {
|
"drives": {
|
||||||
"enabled": Option(False, type=valid_bool),
|
"enabled": Option(False, type=valid_bool),
|
||||||
"count": Option(1, type=valid_int_f1),
|
"count": Option(1, type=valid_int_f1),
|
||||||
"default": {
|
"default": {
|
||||||
"stall": Option(False, type=valid_bool),
|
"stall": Option(False, type=valid_bool),
|
||||||
"cdrom": Option(False, type=valid_bool),
|
"cdrom": Option(False, type=valid_bool),
|
||||||
"rw": Option(True, type=valid_bool),
|
"rw": Option(True, type=valid_bool),
|
||||||
"removable": Option(True, type=valid_bool),
|
"removable": Option(True, type=valid_bool),
|
||||||
"fua": Option(True, type=valid_bool),
|
"fua": Option(True, type=valid_bool),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -96,8 +96,8 @@ def _find_udc(udc: str) -> str:
|
|||||||
|
|
||||||
def _check_config(config: Section) -> None:
|
def _check_config(config: Section) -> None:
|
||||||
if (
|
if (
|
||||||
not config.otg.acm.enabled
|
not config.otg.devices.serial.enabled
|
||||||
and not config.otg.ethernet.enabled
|
and not config.otg.devices.ethernet.enabled
|
||||||
and config.kvmd.hid.type != "otg"
|
and config.kvmd.hid.type != "otg"
|
||||||
and config.kvmd.msd.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")
|
func_path = join(gadget_path, "functions/acm.usb0")
|
||||||
_mkdir(func_path)
|
_mkdir(func_path)
|
||||||
_symlink(func_path, join(config_path, "acm.usb0"))
|
_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, "strings/0x409/configuration"), "Config 1: ECM network")
|
||||||
_write(join(config_path, "MaxPower"), "250")
|
_write(join(config_path, "MaxPower"), "250")
|
||||||
|
|
||||||
if config.otg.acm.enabled:
|
if config.otg.devices.serial.enabled:
|
||||||
logger.info("Required ACM")
|
logger.info("Required Serial")
|
||||||
_create_acm(gadget_path, config_path)
|
_create_serial(gadget_path, config_path)
|
||||||
|
|
||||||
if config.otg.ethernet.enabled:
|
if config.otg.devices.ethernet.enabled:
|
||||||
logger.info("Required Ethernet")
|
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":
|
if config.kvmd.hid.type == "otg":
|
||||||
logger.info("Required HID")
|
logger.info("Required HID")
|
||||||
@ -203,11 +203,11 @@ def _cmd_start(config: Section) -> None:
|
|||||||
|
|
||||||
if config.kvmd.msd.type == "otg":
|
if config.kvmd.msd.type == "otg":
|
||||||
logger.info("Required MSD")
|
logger.info("Required MSD")
|
||||||
_create_msd(gadget_path, config_path, 0, config.otg.msd.user, **config.otg.msd.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.drives.enabled:
|
if config.otg.devices.drives.enabled:
|
||||||
logger.info("Required MSD extra drives: %d", config.otg.drives.count)
|
logger.info("Required MSD extra drives: %d", config.otg.devices.drives.count)
|
||||||
for instance in range(config.otg.drives.count):
|
for instance in range(config.otg.devices.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, instance + 1, "root", **config.otg.devices.drives.default._unpack())
|
||||||
|
|
||||||
logger.info("Enabling the gadget ...")
|
logger.info("Enabling the gadget ...")
|
||||||
_write(join(gadget_path, "UDC"), udc)
|
_write(join(gadget_path, "UDC"), udc)
|
||||||
|
|||||||
@ -33,6 +33,7 @@ disable =
|
|||||||
no-else-return,
|
no-else-return,
|
||||||
len-as-condition,
|
len-as-condition,
|
||||||
raise-missing-from,
|
raise-missing-from,
|
||||||
|
protected-access,
|
||||||
|
|
||||||
[REPORTS]
|
[REPORTS]
|
||||||
msg-template = {symbol} -- {path}:{line}({obj}): {msg}
|
msg-template = {symbol} -- {path}:{line}({obj}): {msg}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user