33 lines
859 B
Python
33 lines
859 B
Python
from __future__ import annotations
|
|
|
|
from collections.abc import Iterator
|
|
from pathlib import Path
|
|
from typing import TYPE_CHECKING, Final, final
|
|
|
|
from autoslot import Slots
|
|
|
|
from docker_compose import ROOT
|
|
|
|
if TYPE_CHECKING:
|
|
from docker_compose.domain.render.render import Render
|
|
|
|
|
|
@final
|
|
class BindVols(Slots):
|
|
def __init__(self, render: Render) -> None:
|
|
self.render: Final = render
|
|
|
|
def __call__(self):
|
|
for path in self:
|
|
path.mkdir(parents=True, exist_ok=True)
|
|
|
|
def __iter__(self) -> Iterator[Path]:
|
|
for app in self.render.template.services:
|
|
for vol in app.volumes:
|
|
path = Path(self.render.org_data(vol.src))
|
|
if ROOT not in path.parents:
|
|
continue
|
|
if not path.is_dir():
|
|
continue
|
|
yield path
|