mirror of
https://github.com/yavook/kiwi-scp.git
synced 2024-11-24 21:52: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
|
# local
|
||||||
from .utils._misc import get_project_name, get_services, list_projects
|
from .utils.misc import get_project_name, get_services, list_projects
|
||||||
|
|
||||||
# parent
|
# parent
|
||||||
from ..parser import Parser
|
from ..parser import Parser
|
||||||
|
@ -71,12 +74,20 @@ class ServiceCommand(ProjectCommand):
|
||||||
class FlexCommand(ServiceCommand):
|
class FlexCommand(ServiceCommand):
|
||||||
"""this command concerns the entire instance, a whole project or just service(s) in a project"""
|
"""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__(
|
super().__init__(
|
||||||
name, num_projects='?', num_services='*',
|
name, num_projects='?', num_services='*',
|
||||||
**kwargs
|
**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):
|
def _run_instance(self, runner, config, args):
|
||||||
result = True
|
result = True
|
||||||
|
|
||||||
|
@ -86,10 +97,10 @@ class FlexCommand(ServiceCommand):
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _run_project(self, runner, config, args, project_name):
|
def _run_project(self, runner, config, args):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _run_services(self, runner, config, args, project_name, services):
|
def _run_services(self, runner, config, args, services):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def run(self, runner, config, args):
|
def run(self, runner, config, args):
|
||||||
|
@ -98,11 +109,14 @@ class FlexCommand(ServiceCommand):
|
||||||
|
|
||||||
if project_name is None:
|
if project_name is None:
|
||||||
# no project given, run for entire instance
|
# no project given, run for entire instance
|
||||||
|
logging.info(f"{self.__action} this instance")
|
||||||
return self._run_instance(runner, config, args)
|
return self._run_instance(runner, config, args)
|
||||||
|
|
||||||
if services is None:
|
if not services:
|
||||||
# no services given, run for whole project
|
# 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
|
# 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
|
# local
|
||||||
from ._subcommand import SubCommand
|
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
|
from .utils.rootkit import Rootkit, prefix_path_mnt
|
||||||
|
|
||||||
# parent
|
# parent
|
||||||
|
|
|
@ -4,7 +4,7 @@ import logging
|
||||||
# local
|
# local
|
||||||
from ._subcommand import FlexCommand
|
from ._subcommand import FlexCommand
|
||||||
from .utils.dockercommand import DockerCommand
|
from .utils.dockercommand import DockerCommand
|
||||||
from .utils._misc import are_you_sure
|
from .utils.misc import are_you_sure
|
||||||
|
|
||||||
|
|
||||||
class DownCommand(FlexCommand):
|
class DownCommand(FlexCommand):
|
||||||
|
@ -12,7 +12,8 @@ class DownCommand(FlexCommand):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(
|
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):
|
def _run_instance(self, runner, config, args):
|
||||||
|
@ -21,17 +22,13 @@ class DownCommand(FlexCommand):
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _run_project(self, runner, config, args, project_name):
|
def _run_project(self, runner, config, args):
|
||||||
logging.info(f"Bringing down project '{project_name}'")
|
|
||||||
|
|
||||||
DockerCommand('docker-compose').run(
|
DockerCommand('docker-compose').run(
|
||||||
config, args, ['down']
|
config, args, ['down']
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _run_services(self, runner, config, args, project_name, services):
|
def _run_services(self, runner, config, args, services):
|
||||||
logging.info(f"Bringing down services {services} in project '{project_name}'")
|
|
||||||
|
|
||||||
DockerCommand('docker-compose').run(
|
DockerCommand('docker-compose').run(
|
||||||
config, args, ['stop', *services]
|
config, args, ['stop', *services]
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import subprocess
|
||||||
# local
|
# local
|
||||||
from ._subcommand import SubCommand
|
from ._subcommand import SubCommand
|
||||||
from .utils.dockercommand import DockerCommand
|
from .utils.dockercommand import DockerCommand
|
||||||
from .utils._misc import are_you_sure
|
from .utils.misc import are_you_sure
|
||||||
|
|
||||||
|
|
||||||
def _find_net(config, args):
|
def _find_net(config, args):
|
||||||
|
|
|
@ -11,20 +11,17 @@ class UpCommand(FlexCommand):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(
|
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):
|
def _run_project(self, runner, config, args):
|
||||||
logging.info(f"Bringing up project '{project_name}'")
|
|
||||||
|
|
||||||
DockerCommand('docker-compose').run(
|
DockerCommand('docker-compose').run(
|
||||||
config, args, ['up', '-d']
|
config, args, ['up', '-d']
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _run_services(self, runner, config, args, project_name, services):
|
def _run_services(self, runner, config, args, services):
|
||||||
logging.info(f"Bringing up services {services} in project '{project_name}'")
|
|
||||||
|
|
||||||
DockerCommand('docker-compose').run(
|
DockerCommand('docker-compose').run(
|
||||||
config, args, ['up', '-d', *services]
|
config, args, ['up', '-d', *services]
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import subprocess
|
||||||
|
|
||||||
# local
|
# local
|
||||||
from .executable import Executable
|
from .executable import Executable
|
||||||
from ._misc import get_project_dir, get_project_name
|
from .misc import get_project_dir, get_project_name
|
||||||
|
|
||||||
# parent
|
# parent
|
||||||
from ..._constants import CONF_DIRECTORY_NAME
|
from ..._constants import CONF_DIRECTORY_NAME
|
||||||
|
|
Loading…
Reference in a new issue