1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2024-11-24 13:43:01 +00:00
kiwi-scp/kiwi_scp/instance.py

43 lines
1.1 KiB
Python
Raw Normal View History

2021-10-22 15:50:26 +00:00
from pathlib import Path
2021-12-02 18:32:38 +00:00
from typing import Generator, Dict, Sequence
2021-10-22 15:50:26 +00:00
import attr
2021-12-02 16:08:14 +00:00
from .config import KiwiConfig
from .project import Project
2021-11-03 15:32:01 +00:00
@attr.s
2021-11-03 15:32:01 +00:00
class Instance:
directory: Path = attr.ib(default=Path('.'))
@property
def config(self) -> KiwiConfig:
"""shorthand: get the current configuration"""
return KiwiConfig.from_directory(self.directory)
@property
def projects(self) -> Generator[Project, None, None]:
2021-12-02 01:38:29 +00:00
for project in self.config.projects:
yield Project(
directory=self.directory.joinpath(project.name),
parent=self,
)
2021-12-02 18:32:38 +00:00
def get_projects(self, project_names: Sequence[str]) -> Dict[str, Project]:
existing_projects = {
project.name: project
for project in self.projects
if project.name in project_names
}
nonexistent_projects = {
name: None
for name in project_names
if name not in existing_projects
}
return {
**existing_projects,
**nonexistent_projects
}