From 5c300b91199a03b51b91c40378ea6ba74ffa2da2 Mon Sep 17 00:00:00 2001 From: ldericher <40151420+ldericher@users.noreply.github.com> Date: Wed, 23 Feb 2022 00:21:29 +0100 Subject: [PATCH 1/3] KIWI_CONFIG handling --- kiwi_scp/instance.py | 4 ++-- kiwi_scp/rootkit.py | 4 +--- kiwi_scp/services.py | 24 ++++-------------------- 3 files changed, 7 insertions(+), 25 deletions(-) diff --git a/kiwi_scp/instance.py b/kiwi_scp/instance.py index c40e1f7..13f6047 100644 --- a/kiwi_scp/instance.py +++ b/kiwi_scp/instance.py @@ -32,8 +32,8 @@ class Instance: return self.directory.joinpath(CONFIG_DIRECTORY_NAME) @property - def storage_config_directory(self): - return self.config.storage.directory.joinpath(CONFIG_DIRECTORY_NAME) + def storage_directory(self): + return self.config.storage.directory @staticmethod def __find_net(net_name): diff --git a/kiwi_scp/rootkit.py b/kiwi_scp/rootkit.py index 1be6ab6..22cade4 100644 --- a/kiwi_scp/rootkit.py +++ b/kiwi_scp/rootkit.py @@ -64,9 +64,7 @@ class Rootkit: return argument elif isinstance(argument, Path): - if argument.is_absolute(): - argument = argument.relative_to("/") - + argument = argument.absolute().relative_to("/") return str(ROOTKIT_PREFIX.joinpath(argument)) elif not isinstance(argument, Sequence): diff --git a/kiwi_scp/services.py b/kiwi_scp/services.py index f1b3455..fc4d20d 100644 --- a/kiwi_scp/services.py +++ b/kiwi_scp/services.py @@ -44,36 +44,20 @@ class Services: yield from service.configs def copy_configs(self) -> None: - path_str_list = TypeVar("path_str_list", Union[Path, str], List[Union[Path, str]]) - - def prefix_path(path: path_str_list, prefix: Path) -> path_str_list: - if isinstance(path, Path): - return prefix.absolute().joinpath(path) - - elif isinstance(path, str): - return prefix_path(Path(path), prefix) - - elif isinstance(path, list): - return [prefix_path(p, prefix) for p in path] - project = self.parent_project + configs = list(self.configs) - if project is None: + if project is None or not configs: return instance = project.parent_instance - cfgs = list(self.configs) - - local_cfgs = prefix_path(cfgs, instance.config_directory) - storage_cfgs = prefix_path(cfgs, instance.storage_config_directory) - storage_dirs = [path.parent for path in storage_cfgs] Rootkit("rsync").run([ - "mkdir", "-p", storage_dirs + "mkdir", "-p", instance.storage_directory ], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) Rootkit("rsync").run([ - "rsync", "-rpt", list(zip(local_cfgs, storage_cfgs)) + "rsync", "-rpt", instance.config_directory, instance.storage_directory ], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) @property From 4f3f9c3bf02ca5a7f77f8637057791ec719c244b Mon Sep 17 00:00:00 2001 From: ldericher <40151420+ldericher@users.noreply.github.com> Date: Wed, 23 Feb 2022 00:21:55 +0100 Subject: [PATCH 2/3] reformat --- kiwi_scp/config.py | 2 +- kiwi_scp/services.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kiwi_scp/config.py b/kiwi_scp/config.py index c60f81c..e5012e7 100644 --- a/kiwi_scp/config.py +++ b/kiwi_scp/config.py @@ -16,7 +16,7 @@ class InvalidFormatError(ValueError): member: Optional[str] data: str - def __init__(self, cls, data, member = None): + def __init__(self, cls, data, member=None): self.cls = cls self.data = data diff --git a/kiwi_scp/services.py b/kiwi_scp/services.py index fc4d20d..8aad20e 100644 --- a/kiwi_scp/services.py +++ b/kiwi_scp/services.py @@ -1,6 +1,6 @@ import subprocess from pathlib import Path -from typing import List, Generator, Optional, TYPE_CHECKING, TypeVar, Union +from typing import List, Generator, Optional, TYPE_CHECKING import attr From fb381cbeca23084846535aaf588ed9cc0452a021 Mon Sep 17 00:00:00 2001 From: ldericher <40151420+ldericher@users.noreply.github.com> Date: Wed, 23 Feb 2022 00:22:17 +0100 Subject: [PATCH 3/3] version bump --- example/kiwi.yml | 2 +- kiwi_scp/config.py | 2 +- pyproject.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/example/kiwi.yml b/example/kiwi.yml index a9f55fa..188a0e8 100644 --- a/example/kiwi.yml +++ b/example/kiwi.yml @@ -2,7 +2,7 @@ # kiwi-scp instance configuration # ################################### -version: 0.2.0 +version: 0.2.1 shells: - /bin/bash diff --git a/kiwi_scp/config.py b/kiwi_scp/config.py index e5012e7..e674a9c 100644 --- a/kiwi_scp/config.py +++ b/kiwi_scp/config.py @@ -164,7 +164,7 @@ class MissingMemberError(ValueError): class KiwiConfig(BaseModel): """represents a kiwi.yml""" - version: constr(regex=RE_SEMVER) = "0.2.0" + version: constr(regex=RE_SEMVER) = "0.2.1" shells: List[Path] = [ Path("/bin/bash"), diff --git a/pyproject.toml b/pyproject.toml index 7407cf8..898f997 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "kiwi-scp" -version = "0.2.0" +version = "0.2.1" description = "kiwi is the simple tool for managing container servers." authors = ["ldericher <40151420+ldericher@users.noreply.github.com>"]