mirror of
https://github.com/yavook/kiwi-scp.git
synced 2024-12-25 18:42:59 +00:00
FlexCommand automatic logging with action creation param
This commit is contained in:
parent
c336de4d9c
commit
6976480dd7
7 changed files with 33 additions and 25 deletions
|
@ -1,5 +1,8 @@
|
|||
# system
|
||||
import logging
|
||||
|
||||
# local
|
||||
from .utils._misc import get_project_name, get_services, list_projects
|
||||
from .utils.misc import get_project_name, get_services, list_projects
|
||||
|
||||
# parent
|
||||
from ..parser import Parser
|
||||
|
@ -71,12 +74,20 @@ class ServiceCommand(ProjectCommand):
|
|||
class FlexCommand(ServiceCommand):
|
||||
"""this command concerns the entire instance, a whole project or just service(s) in a project"""
|
||||
|
||||
def __init__(self, name, **kwargs):
|
||||
__action = None
|
||||
|
||||
def __init__(self, name, action='', **kwargs):
|
||||
super().__init__(
|
||||
name, num_projects='?', num_services='*',
|
||||
**kwargs
|
||||
)
|
||||
|
||||
if not action:
|
||||
# default action string
|
||||
self.__action = f"Running '{str(self)}' for"
|
||||
else:
|
||||
self.__action = action
|
||||
|
||||
def _run_instance(self, runner, config, args):
|
||||
result = True
|
||||
|
||||
|
@ -86,10 +97,10 @@ class FlexCommand(ServiceCommand):
|
|||
|
||||
return result
|
||||
|
||||
def _run_project(self, runner, config, args, project_name):
|
||||
def _run_project(self, runner, config, args):
|
||||
pass
|
||||
|
||||
def _run_services(self, runner, config, args, project_name, services):
|
||||
def _run_services(self, runner, config, args, services):
|
||||
pass
|
||||
|
||||
def run(self, runner, config, args):
|
||||
|
@ -98,11 +109,14 @@ class FlexCommand(ServiceCommand):
|
|||
|
||||
if project_name is None:
|
||||
# no project given, run for entire instance
|
||||
logging.info(f"{self.__action} this instance")
|
||||
return self._run_instance(runner, config, args)
|
||||
|
||||
if services is None:
|
||||
if not services:
|
||||
# no services given, run for whole project
|
||||
return self._run_project(runner, config, args, project_name)
|
||||
logging.info(f"{self.__action} project '{project_name}'")
|
||||
return self._run_project(runner, config, args)
|
||||
|
||||
# run for service(s) inside project
|
||||
return self._run_services(runner, config, args, project_name, services)
|
||||
logging.info(f"{self.__action} services {services} in project '{project_name}'")
|
||||
return self._run_services(runner, config, args, services)
|
||||
|
|
|
@ -5,7 +5,7 @@ import subprocess
|
|||
|
||||
# local
|
||||
from ._subcommand import SubCommand
|
||||
from .utils._misc import list_projects, get_project_dir
|
||||
from .utils.misc import list_projects, get_project_dir
|
||||
from .utils.rootkit import Rootkit, prefix_path_mnt
|
||||
|
||||
# parent
|
||||
|
|
|
@ -4,7 +4,7 @@ import logging
|
|||
# local
|
||||
from ._subcommand import FlexCommand
|
||||
from .utils.dockercommand import DockerCommand
|
||||
from .utils._misc import are_you_sure
|
||||
from .utils.misc import are_you_sure
|
||||
|
||||
|
||||
class DownCommand(FlexCommand):
|
||||
|
@ -12,7 +12,8 @@ class DownCommand(FlexCommand):
|
|||
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
'down', description="Bring down the whole instance, a project or service(s) inside a project"
|
||||
'down', "Bringing down",
|
||||
description="Bring down the whole instance, a project or service(s) inside a project"
|
||||
)
|
||||
|
||||
def _run_instance(self, runner, config, args):
|
||||
|
@ -21,17 +22,13 @@ class DownCommand(FlexCommand):
|
|||
|
||||
return False
|
||||
|
||||
def _run_project(self, runner, config, args, project_name):
|
||||
logging.info(f"Bringing down project '{project_name}'")
|
||||
|
||||
def _run_project(self, runner, config, args):
|
||||
DockerCommand('docker-compose').run(
|
||||
config, args, ['down']
|
||||
)
|
||||
return True
|
||||
|
||||
def _run_services(self, runner, config, args, project_name, services):
|
||||
logging.info(f"Bringing down services {services} in project '{project_name}'")
|
||||
|
||||
def _run_services(self, runner, config, args, services):
|
||||
DockerCommand('docker-compose').run(
|
||||
config, args, ['stop', *services]
|
||||
)
|
||||
|
|
|
@ -5,7 +5,7 @@ import subprocess
|
|||
# local
|
||||
from ._subcommand import SubCommand
|
||||
from .utils.dockercommand import DockerCommand
|
||||
from .utils._misc import are_you_sure
|
||||
from .utils.misc import are_you_sure
|
||||
|
||||
|
||||
def _find_net(config, args):
|
||||
|
|
|
@ -11,20 +11,17 @@ class UpCommand(FlexCommand):
|
|||
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
'up', description="Bring up the whole instance, a project or service(s) inside a project"
|
||||
'up', "Bringing up",
|
||||
description="Bring up the whole instance, a project or service(s) inside a project"
|
||||
)
|
||||
|
||||
def _run_project(self, runner, config, args, project_name):
|
||||
logging.info(f"Bringing up project '{project_name}'")
|
||||
|
||||
def _run_project(self, runner, config, args):
|
||||
DockerCommand('docker-compose').run(
|
||||
config, args, ['up', '-d']
|
||||
)
|
||||
return True
|
||||
|
||||
def _run_services(self, runner, config, args, project_name, services):
|
||||
logging.info(f"Bringing up services {services} in project '{project_name}'")
|
||||
|
||||
def _run_services(self, runner, config, args, services):
|
||||
DockerCommand('docker-compose').run(
|
||||
config, args, ['up', '-d', *services]
|
||||
)
|
||||
|
|
|
@ -5,7 +5,7 @@ import subprocess
|
|||
|
||||
# local
|
||||
from .executable import Executable
|
||||
from ._misc import get_project_dir, get_project_name
|
||||
from .misc import get_project_dir, get_project_name
|
||||
|
||||
# parent
|
||||
from ..._constants import CONF_DIRECTORY_NAME
|
||||
|
|
Loading…
Reference in a new issue