1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2024-11-21 20:33:00 +00:00

new "run_for_filtered_services"

This commit is contained in:
Jörn-Michael Miehe 2021-11-27 18:33:46 +01:00
parent 7afd540062
commit f194ea9356
4 changed files with 33 additions and 24 deletions

View file

@ -6,7 +6,7 @@ from typing import List, Tuple, Iterable, Type, Optional, TypeVar
import click
from ..instance import Instance, Project
from ..instance import Instance, Project, Services
from ..wstring import WParagraph, WAlignment
@ -135,6 +135,20 @@ class KiwiCommand:
@classmethod
def run_for_services(cls, instance: Instance, project: Project, service_names: List[str], **kwargs) -> None:
services = project.services.filter_existing(service_names)
new_service_names = [
service_name
for service_name
in service_names
if service_name not in list(services.names)
]
cls.run_for_filtered_services(instance, project, services, new_service_names, **kwargs)
@classmethod
def run_for_filtered_services(cls, instance: Instance, project: Project, services: Services,
new_service_names: List[str], **kwargs) -> None:
raise Exception

View file

@ -5,7 +5,7 @@ import click
from .cli import KiwiCommand, KiwiCommandType
from .decorators import kiwi_command
from ..executable import COMPOSE_EXE
from ..instance import Instance, Project
from ..instance import Instance, Project, Services
@click.option(
@ -40,15 +40,9 @@ class DownCommand(KiwiCommand):
COMPOSE_EXE.run(["down"], **project.process_kwargs)
@classmethod
def run_for_services(cls, instance: Instance, project: Project, service_names: List[str], **kwargs) -> None:
services = project.services.filter_existing(service_names)
existing_service_names = [
service.name
for service in services.content
]
all_service_names_exist = len(existing_service_names) == len(service_names)
if not existing_service_names and not all_service_names_exist:
def run_for_filtered_services(cls, instance: Instance, project: Project, services: Services,
new_service_names: List[str], **kwargs) -> None:
if not services:
if not click.confirm(
"Did not find any of those services. \n"
f"Bring down the entire project {project.name} instead?",
@ -56,5 +50,5 @@ class DownCommand(KiwiCommand):
):
return
COMPOSE_EXE.run(["stop", *existing_service_names], **project.process_kwargs)
COMPOSE_EXE.run(["rm", "-f", *existing_service_names], **project.process_kwargs)
COMPOSE_EXE.run(["stop", *services.names], **project.process_kwargs)
COMPOSE_EXE.run(["rm", "-f", *services.names], **project.process_kwargs)

View file

@ -5,7 +5,7 @@ import click
from .cli import KiwiCommand, KiwiCommandType
from .decorators import kiwi_command
from ..executable import COMPOSE_EXE
from ..instance import Instance, Project
from ..instance import Instance, Project, Services
@kiwi_command(
@ -16,18 +16,12 @@ class UpCommand(KiwiCommand):
"""Bring up the whole instance, a project or service(s) inside a project"""
@classmethod
def run_for_services(cls, instance: Instance, project: Project, service_names: List[str], **kwargs) -> None:
def run_for_filtered_services(cls, instance: Instance, project: Project, services: Services,
new_service_names: List[str], **kwargs) -> None:
# TODO conf-copy
# TODO net-up
services = project.services.filter_existing(service_names)
existing_service_names = [
service.name
for service in services.content
]
all_service_names_exist = len(existing_service_names) == len(service_names)
if not existing_service_names and not all_service_names_exist:
if not services:
if not click.confirm(
"Did not find any of those services. \n"
f"Bring up the entire project {project.name} instead?",
@ -35,4 +29,4 @@ class UpCommand(KiwiCommand):
):
return
COMPOSE_EXE.run(["up", "-d", *existing_service_names], **project.process_kwargs)
COMPOSE_EXE.run(["up", "-d", *services.names], **project.process_kwargs)

View file

@ -46,6 +46,13 @@ class Services:
def __bool__(self) -> bool:
return bool(self.content)
@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