diff options
author | Maxim Devaev <[email protected]> | 2023-03-05 17:28:45 +0200 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2023-03-05 17:28:45 +0200 |
commit | 7c7ac38bfed8485fd1928cc03025739b6a407d51 (patch) | |
tree | 3ec3bb4ab1050d597dbedfa249ecf6da453944ec /kvmd/plugins | |
parent | b4fa35f05f2d5880b5c655f0be9d3d3871b3ce5f (diff) |
new msd fs structure
Diffstat (limited to 'kvmd/plugins')
-rw-r--r-- | kvmd/plugins/msd/otg/__init__.py | 4 | ||||
-rw-r--r-- | kvmd/plugins/msd/otg/storage.py | 23 |
2 files changed, 14 insertions, 13 deletions
diff --git a/kvmd/plugins/msd/otg/__init__.py b/kvmd/plugins/msd/otg/__init__.py index 13571f3f..52129db5 100644 --- a/kvmd/plugins/msd/otg/__init__.py +++ b/kvmd/plugins/msd/otg/__init__.py @@ -37,8 +37,8 @@ from ....yamlconf import Option from ....validators.basic import valid_bool from ....validators.basic import valid_number -from ....validators.os import valid_printable_filename from ....validators.os import valid_command +from ....validators.kvm import valid_msd_image_name from .... import aiotools from .... import aiohelpers @@ -170,7 +170,7 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes ], type=valid_command), "initial": { - "image": Option("", type=valid_printable_filename, if_empty=""), + "image": Option("", type=valid_msd_image_name, if_empty=""), "cdrom": Option(False, type=valid_bool), }, } diff --git a/kvmd/plugins/msd/otg/storage.py b/kvmd/plugins/msd/otg/storage.py index f9095224..23d6cc60 100644 --- a/kvmd/plugins/msd/otg/storage.py +++ b/kvmd/plugins/msd/otg/storage.py @@ -46,7 +46,7 @@ class Image(_Image): @property def complete(self) -> bool: if self.storage is not None: - return os.path.exists(self.storage._get_complete_path(self)) # pylint: disable=protected-access + return os.path.exists(self.__get_complete_path()) return True @property @@ -83,7 +83,7 @@ class Image(_Image): def set_complete(self, flag: bool) -> None: assert self.storage is not None - path = self.storage._get_complete_path(self) # pylint: disable=protected-access + path = self.__get_complete_path() if flag: open(path, "w").close() # pylint: disable=consider-using-with else: @@ -92,6 +92,9 @@ class Image(_Image): except FileNotFoundError: pass + def __get_complete_path(self) -> str: + return os.path.join(os.path.dirname(self.path), f".__{self.name}.complete") + @dataclasses.dataclass(frozen=True) class StorageSpace: @@ -102,24 +105,20 @@ class StorageSpace: class Storage: def __init__(self, path: str) -> None: self.__path = path - self.__images_path = os.path.join(self.__path, "images") - self.__meta_path = os.path.join(self.__path, "meta") - - def _get_complete_path(self, image: Image) -> str: - return os.path.join(self.__meta_path, image.name + ".complete") def get_watchable_paths(self) -> list[str]: - return [self.__images_path, self.__meta_path] + return [self.__path] def get_images(self) -> dict[str, Image]: return { name: self.get_image_by_name(name) - for name in os.listdir(self.__images_path) + for name in os.listdir(self.__path) + if not name.startswith(".__") and name != "lost+found" } def get_image_by_name(self, name: str) -> Image: assert name - path = os.path.join(self.__images_path, name) + path = os.path.join(self.__path, name) return self.__get_image(name, path) def get_image_by_path(self, path: str) -> Image: @@ -129,8 +128,10 @@ class Storage: def __get_image(self, name: str, path: str) -> Image: assert name + assert not name.startswith(".__") + assert name != "lost+found" assert path - in_storage = (os.path.dirname(path) == self.__images_path) + in_storage = (os.path.dirname(path) == self.__path) return Image(name, path, (self if in_storage else None)) def get_space(self, fatal: bool) -> (StorageSpace | None): |