mirror of
https://github.com/yavook/kiwi-scp.git
synced 2024-12-18 07:53:01 +00:00
renamed generic "parent" props
This commit is contained in:
parent
b4317d5047
commit
cbe4e422e0
7 changed files with 46 additions and 26 deletions
|
@ -27,7 +27,7 @@ class Instance:
|
|||
for project in self.config.projects:
|
||||
yield Project(
|
||||
directory=self.directory.joinpath(project.name),
|
||||
parent=self,
|
||||
parent_instance=self,
|
||||
)
|
||||
|
||||
def get_projects(self, project_names: Sequence[str]) -> Dict[str, Project]:
|
||||
|
|
|
@ -18,7 +18,7 @@ if TYPE_CHECKING:
|
|||
@attr.s
|
||||
class Project:
|
||||
directory: Path = attr.ib()
|
||||
parent: "Instance" = attr.ib()
|
||||
parent_instance: "Instance" = attr.ib()
|
||||
|
||||
@staticmethod
|
||||
@functools.lru_cache(maxsize=10)
|
||||
|
@ -32,14 +32,14 @@ class Project:
|
|||
|
||||
@property
|
||||
def config(self) -> Optional[ProjectConfig]:
|
||||
return self.parent.config.get_project_config(self.name)
|
||||
return self.parent_instance.config.get_project_config(self.name)
|
||||
|
||||
@property
|
||||
def process_kwargs(self) -> Dict[str, Any]:
|
||||
directory: Path = self.directory
|
||||
project_name: str = self.name
|
||||
kiwi_hub_name: str = self.parent.config.network.name
|
||||
target_root_dir: Path = self.parent.config.storage.directory
|
||||
kiwi_hub_name: str = self.parent_instance.config.network.name
|
||||
target_root_dir: Path = self.parent_instance.config.storage.directory
|
||||
conf_dir: Path = target_root_dir.joinpath(CONF_DIRECTORY_NAME)
|
||||
target_dir: Path = target_root_dir.joinpath(project_name)
|
||||
|
||||
|
@ -54,7 +54,7 @@ class Project:
|
|||
},
|
||||
}
|
||||
|
||||
result["env"].update(self.parent.config.environment)
|
||||
result["env"].update(self.parent_instance.config.environment)
|
||||
|
||||
return result
|
||||
|
||||
|
@ -66,6 +66,6 @@ class Project:
|
|||
Service(
|
||||
name=name,
|
||||
content=content,
|
||||
parent=self,
|
||||
parent_project=self,
|
||||
) for name, content in yml["services"].items()
|
||||
])
|
||||
|
|
|
@ -11,6 +11,7 @@ from ruamel.yaml import CommentedMap
|
|||
from .executable import COMPOSE_EXE
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .instance import Instance
|
||||
from .project import Project
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
@ -20,10 +21,14 @@ _logger = logging.getLogger(__name__)
|
|||
class Service:
|
||||
name: str = attr.ib()
|
||||
content: CommentedMap = attr.ib()
|
||||
parent: "Project" = attr.ib()
|
||||
parent_project: "Project" = attr.ib()
|
||||
|
||||
_RE_CONFIGDIR = re.compile(r"^\s*\$(?:CONFIGDIR|{CONFIGDIR})/+(.*)$", flags=re.UNICODE)
|
||||
|
||||
@property
|
||||
def parent_instance(self) -> "Instance":
|
||||
return self.parent_project.parent_instance
|
||||
|
||||
@property
|
||||
def configs(self) -> Generator[Path, None, None]:
|
||||
if "volumes" not in self.content:
|
||||
|
@ -42,7 +47,7 @@ class Service:
|
|||
COMPOSE_EXE.run(
|
||||
["exec", "-T", self.name, "/bin/sh", "-c", f"command -v {exe_name}"],
|
||||
check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||
**self.parent.process_kwargs,
|
||||
**self.parent_project.process_kwargs,
|
||||
)
|
||||
return True
|
||||
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
from typing import List, Generator
|
||||
from pathlib import Path
|
||||
from typing import List, Generator, Optional, TYPE_CHECKING
|
||||
|
||||
import attr
|
||||
|
||||
from .service import Service
|
||||
from .yaml import YAML
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .instance import Instance
|
||||
from .service import Service
|
||||
|
||||
|
||||
@attr.s
|
||||
class Services:
|
||||
content: List[Service] = attr.ib()
|
||||
content: List["Service"] = attr.ib()
|
||||
|
||||
def __str__(self) -> str:
|
||||
return YAML().dump({
|
||||
|
@ -21,14 +25,25 @@ class Services:
|
|||
def __bool__(self) -> bool:
|
||||
return bool(self.content)
|
||||
|
||||
# def copy_configs(self):
|
||||
# configs = (
|
||||
# config
|
||||
# for service in self.content
|
||||
# for config in service.configs
|
||||
# )
|
||||
@property
|
||||
def parent_instance(self) -> Optional["Instance"]:
|
||||
if not self:
|
||||
return
|
||||
|
||||
return self.content[0].parent_instance
|
||||
|
||||
@property
|
||||
def configs(self) -> Generator[Path, None, None]:
|
||||
for service in self.content:
|
||||
yield from service.configs
|
||||
|
||||
# def copy_configs(self) -> None:
|
||||
# instance = self.parent_instance
|
||||
#
|
||||
# print(list(configs))
|
||||
# if instance is None:
|
||||
# return
|
||||
#
|
||||
# print(list(self.configs))
|
||||
#
|
||||
# # Rootkit("rsync").
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ class TestDefault:
|
|||
def test_example(self):
|
||||
p = Project(
|
||||
directory=Path("example/hello-world.project"),
|
||||
parent=None,
|
||||
parent_instance=None,
|
||||
)
|
||||
|
||||
ss = p.services
|
||||
|
@ -31,7 +31,7 @@ class TestDefault:
|
|||
def test_empty(self):
|
||||
p = Project(
|
||||
directory=Path("nonexistent"),
|
||||
parent=None,
|
||||
parent_instance=None,
|
||||
)
|
||||
|
||||
with pytest.raises(FileNotFoundError) as exc_info:
|
||||
|
|
|
@ -10,7 +10,7 @@ class TestDefault:
|
|||
s = Service(
|
||||
name="s",
|
||||
content=CommentedMap(),
|
||||
parent=None,
|
||||
parent_project=None,
|
||||
)
|
||||
|
||||
assert s.name == "s"
|
||||
|
@ -22,7 +22,7 @@ class TestDefault:
|
|||
content=CommentedMap({
|
||||
"image": "repo/image:tag",
|
||||
}),
|
||||
parent=None,
|
||||
parent_project=None,
|
||||
)
|
||||
|
||||
assert s.name == "s"
|
||||
|
@ -39,7 +39,7 @@ class TestDefault:
|
|||
"$TARGETDIR/other/dir:/path/to/other/mountpoint",
|
||||
]
|
||||
}),
|
||||
parent=None,
|
||||
parent_project=None,
|
||||
)
|
||||
|
||||
assert s.name == "s"
|
||||
|
@ -55,7 +55,7 @@ class TestDefault:
|
|||
"$CONFIGDIR/other/config:/path/to/other/config",
|
||||
]
|
||||
}),
|
||||
parent=None,
|
||||
parent_project=None,
|
||||
)
|
||||
|
||||
assert s.name == "s"
|
||||
|
|
|
@ -9,7 +9,7 @@ class TestServices:
|
|||
s = Service(
|
||||
name="s",
|
||||
content=CommentedMap(),
|
||||
parent=None,
|
||||
parent_project=None,
|
||||
)
|
||||
ss = Services([s])
|
||||
|
||||
|
|
Loading…
Reference in a new issue