diff options
author | Maxim Devaev <[email protected]> | 2023-08-06 06:18:51 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2023-08-06 06:18:51 +0300 |
commit | a1b718f6a0911cd3bdc06039d84bdf8e65536169 (patch) | |
tree | 2d587ab4189b5bbadca1f5e713dca2f2cdca3259 /kvmd/apps/otgconf | |
parent | 92c3620a86338061d6ccb476b56fc90f7541b621 (diff) |
kvmd-otgconf: multiple ops
Diffstat (limited to 'kvmd/apps/otgconf')
-rw-r--r-- | kvmd/apps/otgconf/__init__.py | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/kvmd/apps/otgconf/__init__.py b/kvmd/apps/otgconf/__init__.py index 9d672ce8..4e429aba 100644 --- a/kvmd/apps/otgconf/__init__.py +++ b/kvmd/apps/otgconf/__init__.py @@ -66,16 +66,18 @@ class _GadgetControl: with open(os.path.join(self.__meta_path, meta_name)) as file: yield json.loads(file.read()) - def enable_function(self, func: str) -> None: + def enable_functions(self, funcs: list[str]) -> None: with self.__udc_stopped(): - os.symlink( - usb.get_gadget_path(self.__gadget, usb.G_FUNCTIONS, func), - usb.get_gadget_path(self.__gadget, usb.G_PROFILE, func), - ) + for func in funcs: + os.symlink( + usb.get_gadget_path(self.__gadget, usb.G_FUNCTIONS, func), + usb.get_gadget_path(self.__gadget, usb.G_PROFILE, func), + ) - def disable_function(self, func: str) -> None: + def disable_functions(self, funcs: list[str]) -> None: with self.__udc_stopped(): - os.unlink(usb.get_gadget_path(self.__gadget, usb.G_PROFILE, func)) + for func in funcs: + os.unlink(usb.get_gadget_path(self.__gadget, usb.G_PROFILE, func)) def list_functions(self) -> None: for meta in self.__read_metas(): @@ -120,10 +122,8 @@ def main(argv: (list[str] | None)=None) -> None: parents=[parent_parser], ) 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("-e", "--enable-function", nargs="+", metavar="<name>", help="Enable function(s)") + parser.add_argument("-d", "--disable-function", nargs="+", metavar="<name>", help="Disable function(s)") parser.add_argument("-r", "--reset-gadget", action="store_true", help="Reset gadget") parser.add_argument("--make-gpio-config", action="store_true") options = parser.parse_args(argv[1:]) @@ -134,11 +134,13 @@ def main(argv: (list[str] | None)=None) -> None: gc.list_functions() elif options.enable_function: - gc.enable_function(options.enable_function) + funcs = list(map(valid_stripped_string_not_empty, options.enable_function)) + gc.enable_functions(funcs) gc.list_functions() elif options.disable_function: - gc.disable_function(options.disable_function) + funcs = list(map(valid_stripped_string_not_empty, options.disable_function)) + gc.disable_functions(funcs) gc.list_functions() elif options.reset_gadget: |