mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 01:00:29 +08:00
kvmd-otgconf: multiple ops
This commit is contained in:
parent
92c3620a86
commit
a1b718f6a0
@ -66,16 +66,18 @@ class _GadgetControl:
|
|||||||
with open(os.path.join(self.__meta_path, meta_name)) as file:
|
with open(os.path.join(self.__meta_path, meta_name)) as file:
|
||||||
yield json.loads(file.read())
|
yield json.loads(file.read())
|
||||||
|
|
||||||
def enable_function(self, func: str) -> None:
|
def enable_functions(self, funcs: list[str]) -> None:
|
||||||
with self.__udc_stopped():
|
with self.__udc_stopped():
|
||||||
os.symlink(
|
for func in funcs:
|
||||||
usb.get_gadget_path(self.__gadget, usb.G_FUNCTIONS, func),
|
os.symlink(
|
||||||
usb.get_gadget_path(self.__gadget, usb.G_PROFILE, func),
|
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():
|
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:
|
def list_functions(self) -> None:
|
||||||
for meta in self.__read_metas():
|
for meta in self.__read_metas():
|
||||||
@ -120,10 +122,8 @@ def main(argv: (list[str] | None)=None) -> None:
|
|||||||
parents=[parent_parser],
|
parents=[parent_parser],
|
||||||
)
|
)
|
||||||
parser.add_argument("-l", "--list-functions", action="store_true", help="List functions")
|
parser.add_argument("-l", "--list-functions", action="store_true", help="List functions")
|
||||||
parser.add_argument("-e", "--enable-function", type=valid_stripped_string_not_empty,
|
parser.add_argument("-e", "--enable-function", nargs="+", metavar="<name>", help="Enable function(s)")
|
||||||
metavar="<name>", help="Enable function")
|
parser.add_argument("-d", "--disable-function", nargs="+", metavar="<name>", help="Disable function(s)")
|
||||||
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")
|
parser.add_argument("-r", "--reset-gadget", action="store_true", help="Reset gadget")
|
||||||
parser.add_argument("--make-gpio-config", action="store_true")
|
parser.add_argument("--make-gpio-config", action="store_true")
|
||||||
options = parser.parse_args(argv[1:])
|
options = parser.parse_args(argv[1:])
|
||||||
@ -134,11 +134,13 @@ def main(argv: (list[str] | None)=None) -> None:
|
|||||||
gc.list_functions()
|
gc.list_functions()
|
||||||
|
|
||||||
elif options.enable_function:
|
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()
|
gc.list_functions()
|
||||||
|
|
||||||
elif options.disable_function:
|
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()
|
gc.list_functions()
|
||||||
|
|
||||||
elif options.reset_gadget:
|
elif options.reset_gadget:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user