summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2022-04-18 12:15:43 +0300
committerMaxim Devaev <[email protected]>2022-04-18 12:15:43 +0300
commite83764c501ee64a2ba513d071031b7d2320d7b10 (patch)
tree89a06a8534a6ced6e81286915072dbdcdceff477
parentae4509f23425e7c7c2f36c5e4895fe57c6662e46 (diff)
optional serial number
-rw-r--r--kvmd/apps/__init__.py6
-rw-r--r--kvmd/apps/otg/__init__.py5
-rw-r--r--kvmd/yamlconf/__init__.py10
3 files changed, 13 insertions, 8 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py
index 1fc801ae..6d7fa295 100644
--- a/kvmd/apps/__init__.py
+++ b/kvmd/apps/__init__.py
@@ -488,9 +488,9 @@ def _get_config_scheme() -> Dict:
"otg": {
"vendor_id": Option(0x1D6B, type=valid_otg_id), # Linux Foundation
"product_id": Option(0x0104, type=valid_otg_id), # Multifunction Composite Gadget
- "manufacturer": Option("PiKVM"),
- "product": Option("Composite KVM Device"),
- "serial": Option("CAFEBABE"),
+ "manufacturer": Option("PiKVM", type=valid_stripped_string),
+ "product": Option("Composite KVM Device", type=valid_stripped_string),
+ "serial": Option("CAFEBABE", type=valid_stripped_string, if_none=None),
"device_version": Option(-1, type=functools.partial(valid_number, min=-1, max=0xFFFF)),
"usb_version": Option(0x0200, type=valid_otg_id),
"max_power": Option(250, type=functools.partial(valid_number, min=50, max=500)),
diff --git a/kvmd/apps/otg/__init__.py b/kvmd/apps/otg/__init__.py
index 11058a7b..44b1bd84 100644
--- a/kvmd/apps/otg/__init__.py
+++ b/kvmd/apps/otg/__init__.py
@@ -195,7 +195,7 @@ class _GadgetConfig:
_write(join(self.__meta_path, f"{func}@meta.json"), json.dumps({"func": func, "name": name}))
-def _cmd_start(config: Section) -> None: # pylint: disable=too-many-statements
+def _cmd_start(config: Section) -> None: # pylint: disable=too-many-statements,too-many-branches
# https://www.kernel.org/doc/Documentation/usb/gadget_configfs.txt
# https://www.isticktoit.net/?p=1383
@@ -231,7 +231,8 @@ def _cmd_start(config: Section) -> None: # pylint: disable=too-many-statements
_mkdir(lang_path)
_write(join(lang_path, "manufacturer"), config.otg.manufacturer)
_write(join(lang_path, "product"), config.otg.product)
- _write(join(lang_path, "serialnumber"), config.otg.serial)
+ if config.otg.serial is not None:
+ _write(join(lang_path, "serialnumber"), config.otg.serial)
profile_path = join(gadget_path, usb.G_PROFILE)
_mkdir(profile_path)
diff --git a/kvmd/yamlconf/__init__.py b/kvmd/yamlconf/__init__.py
index 04900b86..d32e5fd3 100644
--- a/kvmd/yamlconf/__init__.py
+++ b/kvmd/yamlconf/__init__.py
@@ -119,6 +119,7 @@ class Option:
self,
default: Any,
type: Optional[Callable[[Any], Any]]=None, # pylint: disable=redefined-builtin
+ if_none: Any=Stub,
if_empty: Any=Stub,
only_if: str="",
unpack_as: str="",
@@ -127,6 +128,7 @@ class Option:
self.default = default
self.type: Callable[[Any], Any] = (type or (self.__type(default) if default is not None else str)) # type: ignore
+ self.if_none = if_none
self.if_empty = if_empty
self.only_if = only_if
self.unpack_as = unpack_as
@@ -134,8 +136,8 @@ class Option:
def __repr__(self) -> str:
return (
- f"<Option(default={self.default}, type={self.type}, if_empty={self.if_empty},"
- f" only_if={self.only_if}, unpack_as={self.unpack_as})>"
+ f"<Option(default={self.default}, type={self.type}, if_none={self.if_none},"
+ f" if_empty={self.if_empty}, only_if={self.only_if}, unpack_as={self.unpack_as})>"
)
@@ -179,7 +181,9 @@ def make_config(raw: Dict[str, Any], scheme: Dict[str, Any], _keys: Tuple[str, .
value = option.default
else:
value = raw.get(key, option.default)
- if option.if_empty != Stub and not value:
+ if option.if_none != Stub and value is None:
+ value = option.if_none
+ elif option.if_empty != Stub and not value:
value = option.if_empty
else:
try: