2021-12-02 16:08:14 +00:00
|
|
|
from typing import List, Generator
|
|
|
|
|
|
|
|
import attr
|
|
|
|
|
2022-01-24 17:06:11 +00:00
|
|
|
from .service import Service
|
|
|
|
from .yaml import YAML
|
2021-12-02 16:08:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
@attr.s
|
|
|
|
class Services:
|
|
|
|
content: List[Service] = attr.ib()
|
|
|
|
|
|
|
|
def __str__(self) -> str:
|
|
|
|
return YAML().dump({
|
|
|
|
"services": {
|
|
|
|
service.name: service.content
|
|
|
|
for service in self.content
|
|
|
|
}
|
|
|
|
}).strip()
|
|
|
|
|
|
|
|
def __bool__(self) -> bool:
|
|
|
|
return bool(self.content)
|
|
|
|
|
2022-01-24 17:07:19 +00:00
|
|
|
# def copy_configs(self):
|
|
|
|
# configs = (
|
|
|
|
# config
|
|
|
|
# for service in self.content
|
|
|
|
# for config in service.configs
|
|
|
|
# )
|
|
|
|
#
|
|
|
|
# print(list(configs))
|
|
|
|
#
|
|
|
|
# # Rootkit("rsync").
|
|
|
|
|
2021-12-02 16:08:14 +00:00
|
|
|
@property
|
|
|
|
def names(self) -> Generator[str, None, None]:
|
|
|
|
return (
|
|
|
|
service.name
|
|
|
|
for service in self.content
|
|
|
|
)
|
|
|
|
|
|
|
|
def filter_existing(self, service_names: List[str]) -> "Services":
|
|
|
|
return Services([
|
|
|
|
service
|
|
|
|
for service in self.content
|
|
|
|
if service.name in service_names
|
2022-01-24 17:06:11 +00:00
|
|
|
])
|