进一步的 kvmd 国际化(汉化)支持

This commit is contained in:
mofeng-git
2024-08-12 22:58:01 +08:00
parent 0af0e2b4d0
commit 5b25b3661f
11 changed files with 599 additions and 90 deletions

View File

@@ -27,7 +27,9 @@ import json
import time
import argparse
from os.path import join # pylint: disable=ungrouped-imports
from os.path import join
from ...lanuages import Lanuages
from ...logging import get_logger
@@ -201,13 +203,14 @@ def _cmd_start(config: Section) -> None: # pylint: disable=too-many-statements,
# https://www.isticktoit.net/?p=1383
logger = get_logger()
gettext=Lanuages().gettext
_check_config(config)
udc = usb.find_udc(config.otg.udc)
logger.info("Using UDC %s", udc)
logger.info(gettext("Using UDC %s"), udc)
logger.info("Creating gadget %r ...", config.otg.gadget)
logger.info(gettext("Creating gadget %r ..."), config.otg.gadget)
gadget_path = usb.get_gadget_path(config.otg.gadget)
_mkdir(gadget_path)
@@ -248,39 +251,39 @@ def _cmd_start(config: Section) -> None: # pylint: disable=too-many-statements,
cod = config.otg.devices
if cod.serial.enabled:
logger.info("===== Serial =====")
logger.info(gettext("===== Serial ====="))
gc.add_serial(cod.serial.start)
if cod.ethernet.enabled:
logger.info("===== Ethernet =====")
logger.info(gettext("===== Ethernet ====="))
gc.add_ethernet(**cod.ethernet._unpack(ignore=["enabled"]))
if config.kvmd.hid.type == "otg":
logger.info("===== HID-Keyboard =====")
logger.info(gettext("===== HID-Keyboard ====="))
gc.add_keyboard(cod.hid.keyboard.start, config.otg.remote_wakeup)
logger.info("===== HID-Mouse =====")
logger.info(gettext("===== HID-Mouse ====="))
gc.add_mouse(cod.hid.mouse.start, config.otg.remote_wakeup, config.kvmd.hid.mouse.absolute, config.kvmd.hid.mouse.horizontal_wheel)
if config.kvmd.hid.mouse_alt.device:
logger.info("===== HID-Mouse-Alt =====")
logger.info(gettext("===== HID-Mouse-Alt ====="))
gc.add_mouse(cod.hid.mouse.start, config.otg.remote_wakeup, (not config.kvmd.hid.mouse.absolute), config.kvmd.hid.mouse.horizontal_wheel)
if config.kvmd.msd.type == "otg":
logger.info("===== MSD =====")
logger.info(gettext("===== MSD ====="))
gc.add_msd(cod.msd.start, config.otg.user, **cod.msd.default._unpack())
if cod.drives.enabled:
for count in range(cod.drives.count):
logger.info("===== MSD Extra: %d =====", count + 1)
logger.info(gettext("===== MSD Extra: %d ====="), count + 1)
gc.add_msd(cod.drives.start, "root", **cod.drives.default._unpack())
logger.info("===== Preparing complete =====")
logger.info(gettext("===== Preparing complete ====="))
logger.info("Enabling the gadget ...")
logger.info(gettext("Enabling the gadget ..."))
_write(join(gadget_path, "UDC"), udc)
time.sleep(config.otg.init_delay)
_chown(join(gadget_path, "UDC"), config.otg.user)
_chown(profile_path, config.otg.user)
logger.info("Ready to work")
logger.info(gettext("Ready to work"))
# =====
@@ -293,7 +296,7 @@ def _cmd_stop(config: Section) -> None:
gadget_path = usb.get_gadget_path(config.otg.gadget)
logger.info("Disabling gadget %r ...", config.otg.gadget)
logger.info(Lanuages().gettext("Disabling gadget %r ..."), config.otg.gadget)
_write(join(gadget_path, "UDC"), "\n")
_unlink(join(gadget_path, "os_desc", usb.G_PROFILE_NAME), optional=True)