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:
|
for project in self.config.projects:
|
||||||
yield Project(
|
yield Project(
|
||||||
directory=self.directory.joinpath(project.name),
|
directory=self.directory.joinpath(project.name),
|
||||||
parent=self,
|
parent_instance=self,
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_projects(self, project_names: Sequence[str]) -> Dict[str, Project]:
|
def get_projects(self, project_names: Sequence[str]) -> Dict[str, Project]:
|
||||||
|
|
|
@ -18,7 +18,7 @@ if TYPE_CHECKING:
|
||||||
@attr.s
|
@attr.s
|
||||||
class Project:
|
class Project:
|
||||||
directory: Path = attr.ib()
|
directory: Path = attr.ib()
|
||||||
parent: "Instance" = attr.ib()
|
parent_instance: "Instance" = attr.ib()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@functools.lru_cache(maxsize=10)
|
@functools.lru_cache(maxsize=10)
|
||||||
|
@ -32,14 +32,14 @@ class Project:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def config(self) -> Optional[ProjectConfig]:
|
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
|
@property
|
||||||
def process_kwargs(self) -> Dict[str, Any]:
|
def process_kwargs(self) -> Dict[str, Any]:
|
||||||
directory: Path = self.directory
|
directory: Path = self.directory
|
||||||
project_name: str = self.name
|
project_name: str = self.name
|
||||||
kiwi_hub_name: str = self.parent.config.network.name
|
kiwi_hub_name: str = self.parent_instance.config.network.name
|
||||||
target_root_dir: Path = self.parent.config.storage.directory
|
target_root_dir: Path = self.parent_instance.config.storage.directory
|
||||||
conf_dir: Path = target_root_dir.joinpath(CONF_DIRECTORY_NAME)
|
conf_dir: Path = target_root_dir.joinpath(CONF_DIRECTORY_NAME)
|
||||||
target_dir: Path = target_root_dir.joinpath(project_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
|
return result
|
||||||
|
|
||||||
|
@ -66,6 +66,6 @@ class Project:
|
||||||
Service(
|
Service(
|
||||||
name=name,
|
name=name,
|
||||||
content=content,
|
content=content,
|
||||||
parent=self,
|
parent_project=self,
|
||||||
) for name, content in yml["services"].items()
|
) for name, content in yml["services"].items()
|
||||||
])
|
])
|
||||||
|
|
|
@ -11,6 +11,7 @@ from ruamel.yaml import CommentedMap
|
||||||
from .executable import COMPOSE_EXE
|
from .executable import COMPOSE_EXE
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from .instance import Instance
|
||||||
from .project import Project
|
from .project import Project
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
@ -20,10 +21,14 @@ _logger = logging.getLogger(__name__)
|
||||||
class Service:
|
class Service:
|
||||||
name: str = attr.ib()
|
name: str = attr.ib()
|
||||||
content: CommentedMap = 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)
|
_RE_CONFIGDIR = re.compile(r"^\s*\$(?:CONFIGDIR|{CONFIGDIR})/+(.*)$", flags=re.UNICODE)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def parent_instance(self) -> "Instance":
|
||||||
|
return self.parent_project.parent_instance
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def configs(self) -> Generator[Path, None, None]:
|
def configs(self) -> Generator[Path, None, None]:
|
||||||
if "volumes" not in self.content:
|
if "volumes" not in self.content:
|
||||||
|
@ -42,7 +47,7 @@ class Service:
|
||||||
COMPOSE_EXE.run(
|
COMPOSE_EXE.run(
|
||||||
["exec", "-T", self.name, "/bin/sh", "-c", f"command -v {exe_name}"],
|
["exec", "-T", self.name, "/bin/sh", "-c", f"command -v {exe_name}"],
|
||||||
check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||||
**self.parent.process_kwargs,
|
**self.parent_project.process_kwargs,
|
||||||
)
|
)
|
||||||
return True
|
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
|
import attr
|
||||||
|
|
||||||
from .service import Service
|
|
||||||
from .yaml import YAML
|
from .yaml import YAML
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from .instance import Instance
|
||||||
|
from .service import Service
|
||||||
|
|
||||||
|
|
||||||
@attr.s
|
@attr.s
|
||||||
class Services:
|
class Services:
|
||||||
content: List[Service] = attr.ib()
|
content: List["Service"] = attr.ib()
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return YAML().dump({
|
return YAML().dump({
|
||||||
|
@ -21,14 +25,25 @@ class Services:
|
||||||
def __bool__(self) -> bool:
|
def __bool__(self) -> bool:
|
||||||
return bool(self.content)
|
return bool(self.content)
|
||||||
|
|
||||||
# def copy_configs(self):
|
@property
|
||||||
# configs = (
|
def parent_instance(self) -> Optional["Instance"]:
|
||||||
# config
|
if not self:
|
||||||
# for service in self.content
|
return
|
||||||
# for config in service.configs
|
|
||||||
# )
|
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").
|
# # Rootkit("rsync").
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ class TestDefault:
|
||||||
def test_example(self):
|
def test_example(self):
|
||||||
p = Project(
|
p = Project(
|
||||||
directory=Path("example/hello-world.project"),
|
directory=Path("example/hello-world.project"),
|
||||||
parent=None,
|
parent_instance=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
ss = p.services
|
ss = p.services
|
||||||
|
@ -31,7 +31,7 @@ class TestDefault:
|
||||||
def test_empty(self):
|
def test_empty(self):
|
||||||
p = Project(
|
p = Project(
|
||||||
directory=Path("nonexistent"),
|
directory=Path("nonexistent"),
|
||||||
parent=None,
|
parent_instance=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
with pytest.raises(FileNotFoundError) as exc_info:
|
with pytest.raises(FileNotFoundError) as exc_info:
|
||||||
|
|
|
@ -10,7 +10,7 @@ class TestDefault:
|
||||||
s = Service(
|
s = Service(
|
||||||
name="s",
|
name="s",
|
||||||
content=CommentedMap(),
|
content=CommentedMap(),
|
||||||
parent=None,
|
parent_project=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert s.name == "s"
|
assert s.name == "s"
|
||||||
|
@ -22,7 +22,7 @@ class TestDefault:
|
||||||
content=CommentedMap({
|
content=CommentedMap({
|
||||||
"image": "repo/image:tag",
|
"image": "repo/image:tag",
|
||||||
}),
|
}),
|
||||||
parent=None,
|
parent_project=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert s.name == "s"
|
assert s.name == "s"
|
||||||
|
@ -39,7 +39,7 @@ class TestDefault:
|
||||||
"$TARGETDIR/other/dir:/path/to/other/mountpoint",
|
"$TARGETDIR/other/dir:/path/to/other/mountpoint",
|
||||||
]
|
]
|
||||||
}),
|
}),
|
||||||
parent=None,
|
parent_project=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert s.name == "s"
|
assert s.name == "s"
|
||||||
|
@ -55,7 +55,7 @@ class TestDefault:
|
||||||
"$CONFIGDIR/other/config:/path/to/other/config",
|
"$CONFIGDIR/other/config:/path/to/other/config",
|
||||||
]
|
]
|
||||||
}),
|
}),
|
||||||
parent=None,
|
parent_project=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert s.name == "s"
|
assert s.name == "s"
|
||||||
|
|
|
@ -9,7 +9,7 @@ class TestServices:
|
||||||
s = Service(
|
s = Service(
|
||||||
name="s",
|
name="s",
|
||||||
content=CommentedMap(),
|
content=CommentedMap(),
|
||||||
parent=None,
|
parent_project=None,
|
||||||
)
|
)
|
||||||
ss = Services([s])
|
ss = Services([s])
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue