1d2c18eaae
test / run tests/run_tests.py (pull_request) Successful in 13s
'bottles' was the package name when it held a single Bottle Protocol; since we added BottlePlatform / BottlePlan / BottleCleanupPlan and made it the home of platform dispatch, 'platform' describes the package better. The 'bottle' concept (and the manifest field) stays. CLI imports update from ..bottles to ..platform; internal relative imports inside the package survive the rename unchanged. Git detected all 7 file renames.
37 lines
1.0 KiB
Python
37 lines
1.0 KiB
Python
"""DockerBottleCleanupPlan — concrete subclass of BottleCleanupPlan.
|
|
|
|
Holds the tuples of container and network names that
|
|
DockerBottlePlatform.cleanup will remove. The y/N preflight reads
|
|
these via `print`; the CLI short-circuits via `empty`.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from dataclasses import dataclass
|
|
|
|
from ...log import info
|
|
from .. import BottleCleanupPlan
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class DockerBottleCleanupPlan(BottleCleanupPlan):
|
|
"""Resources DockerBottlePlatform.cleanup will remove. Produced by
|
|
`prepare_cleanup` from a snapshot of `docker ps -a` + `docker
|
|
network ls`; sorted so the y/N output is stable."""
|
|
|
|
containers: tuple[str, ...]
|
|
networks: tuple[str, ...]
|
|
|
|
@property
|
|
def empty(self) -> bool:
|
|
return not self.containers and not self.networks
|
|
|
|
def print(self) -> None:
|
|
print(file=sys.stderr)
|
|
for name in self.containers:
|
|
info(f"container: {name}")
|
|
for name in self.networks:
|
|
info(f"network: {name}")
|
|
print(file=sys.stderr)
|