mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 09:10:30 +08:00
kvmd-otgconf --reset-gadget
This commit is contained in:
parent
6828a0e6aa
commit
0dea368d72
@ -62,17 +62,17 @@ def _udc_stopped(gadget: str, udc: str) -> Generator[None, None, None]:
|
|||||||
udc_file.write(udc)
|
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):
|
with _udc_stopped(gadget, udc):
|
||||||
os.symlink(_make_func_path(gadget, func), _make_config_path(gadget, func))
|
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):
|
with _udc_stopped(gadget, udc):
|
||||||
os.unlink(_make_config_path(gadget, func))
|
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)):
|
for meta_name in sorted(os.listdir(meta_path)):
|
||||||
with open(os.path.join(meta_path, meta_name)) as meta_file:
|
with open(os.path.join(meta_path, meta_name)) as meta_file:
|
||||||
meta = json.loads(meta_file.read())
|
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']}")
|
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:
|
def main(argv: Optional[List[str]]=None) -> None:
|
||||||
(parent_parser, argv, config) = init(
|
(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",
|
description="KVMD OTG low-level runtime configuration tool",
|
||||||
parents=[parent_parser],
|
parents=[parent_parser],
|
||||||
)
|
)
|
||||||
parser.add_argument("-l", "--list-funcs", action="store_true", help="List functions")
|
parser.add_argument("-l", "--list-functions", 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("-e", "--enable-function", type=valid_stripped_string_not_empty,
|
||||||
parser.add_argument("-d", "--disable-func", type=valid_stripped_string_not_empty, metavar="<name>", help="Disable function")
|
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:])
|
options = parser.parse_args(argv[1:])
|
||||||
|
|
||||||
if options.enable_func:
|
if options.reset_gadget:
|
||||||
_enable_func(config.otg.gadget, config.otg.udc, options.enable_func)
|
_reset_gadget(config.otg.gadget, config.otg.udc)
|
||||||
|
return
|
||||||
if options.disable_func:
|
elif options.enable_function:
|
||||||
_disable_func(config.otg.gadget, config.otg.udc, options.disable_func)
|
_enable_function(config.otg.gadget, config.otg.udc, options.enable_function)
|
||||||
|
elif options.disable_function:
|
||||||
_list_funcs(config.otg.gadget, config.otg.meta)
|
_disable_function(config.otg.gadget, config.otg.udc, options.disable_function)
|
||||||
|
_list_functions(config.otg.gadget, config.otg.meta)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user