mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 01:00:29 +08:00
renamed some msd methods
This commit is contained in:
parent
921d7da513
commit
2189512e0b
@ -399,7 +399,7 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
|
|||||||
|
|
||||||
async def __STORAGE_create_new_image(self, name: str) -> Image: # pylint: disable=invalid-name
|
async def __STORAGE_create_new_image(self, name: str) -> Image: # pylint: disable=invalid-name
|
||||||
assert self.__state.storage
|
assert self.__state.storage
|
||||||
image = await self.__storage.get_image_by_name(name)
|
image = await self.__storage.make_image_by_name(name)
|
||||||
if image.name in self.__state.storage.images or (await image.exists()):
|
if image.name in self.__state.storage.images or (await image.exists()):
|
||||||
raise MsdImageExistsError()
|
raise MsdImageExistsError()
|
||||||
return image
|
return image
|
||||||
@ -461,7 +461,7 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
|
|||||||
logger = get_logger(0)
|
logger = get_logger(0)
|
||||||
async with self.__state._lock: # pylint: disable=protected-access
|
async with self.__state._lock: # pylint: disable=protected-access
|
||||||
try:
|
try:
|
||||||
drive_state = await self.__get_drive_state()
|
drive_state = await self.__make_init_drive_state()
|
||||||
|
|
||||||
if self.__state.vd is None and drive_state.image is None:
|
if self.__state.vd is None and drive_state.image is None:
|
||||||
# Если только что включились и образ не подключен - попробовать
|
# Если только что включились и образ не подключен - попробовать
|
||||||
@ -471,7 +471,7 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
|
|||||||
await self.__storage.remount_rw(False)
|
await self.__storage.remount_rw(False)
|
||||||
await self.__setup_initial()
|
await self.__setup_initial()
|
||||||
|
|
||||||
storage_state = await self.__get_storage_state()
|
storage_state = await self.__make_init_storage_state()
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception("Error while reloading MSD state; switching to offline")
|
logger.exception("Error while reloading MSD state; switching to offline")
|
||||||
@ -500,7 +500,7 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
|
|||||||
async def __setup_initial(self) -> None:
|
async def __setup_initial(self) -> None:
|
||||||
if self.__initial_image:
|
if self.__initial_image:
|
||||||
logger = get_logger(0)
|
logger = get_logger(0)
|
||||||
image = await self.__storage.get_image_by_name(self.__initial_image)
|
image = await self.__storage.make_image_by_name(self.__initial_image)
|
||||||
if (await image.exists()):
|
if (await image.exists()):
|
||||||
logger.info("Setting up initial image %r ...", self.__initial_image)
|
logger.info("Setting up initial image %r ...", self.__initial_image)
|
||||||
try:
|
try:
|
||||||
@ -514,7 +514,7 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
|
|||||||
|
|
||||||
# =====
|
# =====
|
||||||
|
|
||||||
async def __get_storage_state(self) -> _StorageState:
|
async def __make_init_storage_state(self) -> _StorageState:
|
||||||
images = await self.__storage.get_images()
|
images = await self.__storage.get_images()
|
||||||
space = self.__storage.get_space(fatal=True)
|
space = self.__storage.get_space(fatal=True)
|
||||||
assert space
|
assert space
|
||||||
@ -524,10 +524,10 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
|
|||||||
images=images,
|
images=images,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def __get_drive_state(self) -> _DriveState:
|
async def __make_init_drive_state(self) -> _DriveState:
|
||||||
path = self.__drive.get_image_path()
|
path = self.__drive.get_image_path()
|
||||||
return _DriveState(
|
return _DriveState(
|
||||||
image=((await self.__storage.get_image_by_path(path)) if path else None),
|
image=((await self.__storage.make_image_by_path(path)) if path else None),
|
||||||
cdrom=self.__drive.get_cdrom_flag(),
|
cdrom=self.__drive.get_cdrom_flag(),
|
||||||
rw=self.__drive.get_rw_flag(),
|
rw=self.__drive.get_rw_flag(),
|
||||||
)
|
)
|
||||||
|
|||||||
@ -80,7 +80,7 @@ class Image(_Image):
|
|||||||
path = self.path
|
path = self.path
|
||||||
while not os.path.ismount(path):
|
while not os.path.ismount(path):
|
||||||
path = os.path.dirname(path)
|
path = os.path.dirname(path)
|
||||||
return (self.__storage.get_root_path() != path)
|
return (self.__storage._get_root_path() != path)
|
||||||
|
|
||||||
async def __is_complete(self) -> bool:
|
async def __is_complete(self) -> bool:
|
||||||
if self.__storage:
|
if self.__storage:
|
||||||
@ -150,7 +150,7 @@ class Storage:
|
|||||||
self.__path = path
|
self.__path = path
|
||||||
self.__remount_cmd = remount_cmd
|
self.__remount_cmd = remount_cmd
|
||||||
|
|
||||||
def get_root_path(self) -> str:
|
def _get_root_path(self) -> str:
|
||||||
return self.__path
|
return self.__path
|
||||||
|
|
||||||
async def get_watchable_paths(self) -> list[str]:
|
async def get_watchable_paths(self) -> list[str]:
|
||||||
@ -158,7 +158,7 @@ class Storage:
|
|||||||
|
|
||||||
async def get_images(self) -> dict[str, Image]:
|
async def get_images(self) -> dict[str, Image]:
|
||||||
return {
|
return {
|
||||||
name: (await self.get_image_by_name(name))
|
name: (await self.make_image_by_name(name))
|
||||||
for name in (await aiotools.run_async(self.__inner_get_images))
|
for name in (await aiotools.run_async(self.__inner_get_images))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,12 +192,12 @@ class Storage:
|
|||||||
|
|
||||||
# =====
|
# =====
|
||||||
|
|
||||||
async def get_image_by_name(self, name: str) -> Image:
|
async def make_image_by_name(self, name: str) -> Image:
|
||||||
assert name
|
assert name
|
||||||
path = os.path.join(self.__path, name)
|
path = os.path.join(self.__path, name)
|
||||||
return (await self.__get_image(name, path, True))
|
return (await self.__get_image(name, path, True))
|
||||||
|
|
||||||
async def get_image_by_path(self, path: str) -> Image:
|
async def make_image_by_path(self, path: str) -> Image:
|
||||||
assert path
|
assert path
|
||||||
in_storage = (os.path.commonpath([self.__path, path]) == self.__path)
|
in_storage = (os.path.commonpath([self.__path, path]) == self.__path)
|
||||||
if in_storage:
|
if in_storage:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user