summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2022-03-31 12:01:26 +0300
committerMaxim Devaev <[email protected]>2022-03-31 12:06:23 +0300
commit0dea368d72e5980408b4c22d82a2c0f7f9b2447a (patch)
tree756d32f35859814d79f85455d1462732331c8f55
parent6828a0e6aaa2ab0e95ac9f84980aa17805c3f3ba (diff)
kvmd-otgconf --reset-gadget
-rw-r--r--kvmd/apps/otgconf/__init__.py35
1 files changed, 22 insertions, 13 deletions
diff --git a/kvmd/apps/otgconf/__init__.py b/kvmd/apps/otgconf/__init__.py
index bfbc4326..97d822fa 100644
--- a/kvmd/apps/otgconf/__init__.py
+++ b/kvmd/apps/otgconf/__init__.py
@@ -62,17 +62,17 @@ def _udc_stopped(gadget: str, udc: str) -> Generator[None, None, None]:
udc_file.write(udc)
-def _enable_func(gadget: str, udc: str, func: str) -> None:
+def _enable_function(gadget: str, udc: str, func: str) -> None:
with _udc_stopped(gadget, udc):
os.symlink(_make_func_path(gadget, func), _make_config_path(gadget, func))
-def _disable_func(gadget: str, udc: str, func: str) -> None:
+def _disable_function(gadget: str, udc: str, func: str) -> None:
with _udc_stopped(gadget, udc):
os.unlink(_make_config_path(gadget, func))
-def _list_funcs(gadget: str, meta_path: str) -> None:
+def _list_functions(gadget: str, meta_path: str) -> None:
for meta_name in sorted(os.listdir(meta_path)):
with open(os.path.join(meta_path, meta_name)) as meta_file:
meta = json.loads(meta_file.read())
@@ -80,6 +80,11 @@ def _list_funcs(gadget: str, meta_path: str) -> None:
print(f"{'+' if enabled else '-'} {meta['func']} # {meta['name']}")
+def _reset_gadget(gadget: str, udc: str) -> None:
+ with _udc_stopped(gadget, udc):
+ pass
+
+
# =====
def main(argv: Optional[List[str]]=None) -> None:
(parent_parser, argv, config) = init(
@@ -91,15 +96,19 @@ def main(argv: Optional[List[str]]=None) -> None:
description="KVMD OTG low-level runtime configuration tool",
parents=[parent_parser],
)
- parser.add_argument("-l", "--list-funcs", action="store_true", help="List functions")
- parser.add_argument("-e", "--enable-func", type=valid_stripped_string_not_empty, metavar="<name>", help="Enable function")
- parser.add_argument("-d", "--disable-func", type=valid_stripped_string_not_empty, metavar="<name>", help="Disable function")
+ parser.add_argument("-l", "--list-functions", action="store_true", help="List functions")
+ parser.add_argument("-e", "--enable-function", type=valid_stripped_string_not_empty,
+ metavar="<name>", help="Enable function")
+ parser.add_argument("-d", "--disable-function", type=valid_stripped_string_not_empty,
+ metavar="<name>", help="Disable function")
+ parser.add_argument("-r", "--reset-gadget", action="store_true", help="Reset gadget")
options = parser.parse_args(argv[1:])
- if options.enable_func:
- _enable_func(config.otg.gadget, config.otg.udc, options.enable_func)
-
- if options.disable_func:
- _disable_func(config.otg.gadget, config.otg.udc, options.disable_func)
-
- _list_funcs(config.otg.gadget, config.otg.meta)
+ if options.reset_gadget:
+ _reset_gadget(config.otg.gadget, config.otg.udc)
+ return
+ elif options.enable_function:
+ _enable_function(config.otg.gadget, config.otg.udc, options.enable_function)
+ elif options.disable_function:
+ _disable_function(config.otg.gadget, config.otg.udc, options.disable_function)
+ _list_functions(config.otg.gadget, config.otg.meta)