Revert "初步的 kvmd 国际化(汉化)支持"

This reverts commit 20927c7226.
This commit is contained in:
mofeng-git
2024-11-20 11:54:27 +00:00
parent 8fdb7d7cd6
commit 6928fab16c
34 changed files with 114 additions and 1000 deletions

View File

@@ -40,7 +40,6 @@ from ... import aiotools
from .. import BasePlugin
from .. import get_plugin_class
from ...lanuages import Lanuages
# =====
class MsdError(Exception):
@@ -53,44 +52,37 @@ class MsdOperationError(OperationError, MsdError):
class MsdIsBusyError(IsBusyError, MsdError):
def __init__(self) -> None:
gettext=Lanuages().gettext
super().__init__(gettext("Performing another MSD operation, please try again later"))
super().__init__("Performing another MSD operation, please try again later")
class MsdOfflineError(MsdOperationError):
def __init__(self) -> None:
gettext=Lanuages().gettext
super().__init__(gettext("MSD is not found"))
super().__init__("MSD is not found")
class MsdConnectedError(MsdOperationError):
def __init__(self) -> None:
gettext=Lanuages().gettext
super().__init__(gettext("MSD is connected to Server, but shouldn't for this operation"))
super().__init__("MSD is connected to Server, but shouldn't for this operation")
class MsdDisconnectedError(MsdOperationError):
def __init__(self) -> None:
gettext=Lanuages().gettext
super().__init__(gettext("MSD is disconnected from Server, but should be for this operation"))
super().__init__("MSD is disconnected from Server, but should be for this operation")
class MsdImageNotSelected(MsdOperationError):
def __init__(self) -> None:
gettext=Lanuages().gettext
super().__init__(gettext("The image is not selected"))
super().__init__("The image is not selected")
class MsdUnknownImageError(MsdOperationError):
def __init__(self) -> None:
gettext=Lanuages().gettext
super().__init__(gettext("The image is not found in the storage"))
super().__init__("The image is not found in the storage")
class MsdImageExistsError(MsdOperationError):
def __init__(self) -> None:
gettext=Lanuages().gettext
super().__init__(gettext("This image is already exists"))
super().__init__("This image is already exists")
# =====

View File

@@ -31,13 +31,11 @@ from . import BaseMsdReader
from . import BaseMsdWriter
from . import BaseMsd
from ...lanuages import Lanuages
# =====
class MsdDisabledError(MsdOperationError):
def __init__(self) -> None:
gettext=Lanuages().gettext
super().__init__(gettext("MSD is disabled"))
super().__init__("MSD is disabled")
# =====

View File

@@ -29,7 +29,6 @@ import os
from typing import AsyncGenerator
from ....lanuages import Lanuages
from ....logging import get_logger
from ....inotify import InotifyMask
@@ -45,8 +44,6 @@ from ....validators.kvm import valid_msd_image_name
from .... import aiotools
from .... import fstab
from ....lanuages import Lanuages
from .. import MsdIsBusyError
from .. import MsdOfflineError
from .. import MsdConnectedError
@@ -62,6 +59,7 @@ from .storage import Image
from .storage import Storage
from .drive import Drive
# =====
@dataclasses.dataclass(frozen=True)
class _DriveState:
@@ -143,10 +141,9 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
self.__notifier = aiotools.AioNotifier()
self.__state = _State(self.__notifier)
self.gettext=Lanuages().gettext
logger = get_logger(0)
logger.info(self.gettext("Using OTG gadget %r as MSD"), gadget)
logger.info("Using OTG gadget %r as MSD", gadget)
aiotools.run_sync(self.__reload_state(notify=False))
@classmethod
@@ -221,7 +218,7 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
self.__drive.set_rw_flag(False)
await self.__storage.remount_rw(False)
except Exception:
get_logger(0).exception(self.gettext("Can't reset MSD properly"))
get_logger(0).exception("Can't reset MSD properly")
@aiotools.atomic_fg
async def cleanup(self) -> None:
@@ -450,7 +447,7 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
if need_reload_state:
await self.__reload_state()
except Exception:
logger.exception(self.gettext("Unexpected MSD watcher error"))
logger.exception("Unexpected MSD watcher error")
time.sleep(1)
async def __reload_state(self, notify: bool=True) -> None:
@@ -469,13 +466,13 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
if self.__state.vd is None and drive_state.image is None:
# Если только что включились и образ не подключен - попробовать
# перемонтировать хранилище (и создать images и meta).
logger.info(self.gettext("Probing to remount storage ..."))
logger.info("Probing to remount storage ...")
await self.__storage.remount_rw(True)
await self.__storage.remount_rw(False)
await self.__setup_initial()
except Exception:
logger.exception(self.gettext("Error while reloading MSD state; switching to offline"))
logger.exception("Error while reloading MSD state; switching to offline")
self.__state.storage = None
self.__state.vd = None
@@ -503,12 +500,12 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
logger = get_logger(0)
image = await self.__storage.make_image_by_name(self.__initial_image)
if (await image.exists()):
logger.info(self.gettext("Setting up initial image %r ..."), self.__initial_image)
logger.info("Setting up initial image %r ...", self.__initial_image)
try:
self.__drive.set_rw_flag(False)
self.__drive.set_cdrom_flag(self.__initial_cdrom)
self.__drive.set_image_path(image.path)
except Exception:
logger.exception(self.gettext("Can't setup initial image: ignored"))
logger.exception("Can't setup initial image: ignored")
else:
logger.error(self.gettext("Can't find initial image %r: ignored"), self.__initial_image)
logger.error("Can't find initial image %r: ignored", self.__initial_image)

View File

@@ -27,13 +27,11 @@ from .... import usb
from .. import MsdOperationError
from ....lanuages import Lanuages
# =====
class MsdDriveLockedError(MsdOperationError):
def __init__(self) -> None:
super().__init__(Lanuages().gettext("MSD drive is locked on IO operation"))
super().__init__("MSD drive is locked on IO operation")
# =====

View File

@@ -31,8 +31,6 @@ from typing import Optional
import aiofiles
import aiofiles.os
from ....lanuages import Lanuages
from .... import aiotools
from .... import aiohelpers
@@ -294,4 +292,4 @@ class Storage(_StorageDc):
async def remount_rw(self, rw: bool, fatal: bool=True) -> None:
if not (await aiohelpers.remount("MSD", self.__remount_cmd, rw)):
if fatal:
raise MsdError(Lanuages().gettext("Can't execute remount helper"))
raise MsdError("Can't execute remount helper")