mirror of
https://github.com/yavook/kiwi-scp.git
synced 2024-11-22 04:43:00 +00:00
FlexCommand: project_name / services in params
This commit is contained in:
parent
6615982e95
commit
c336de4d9c
8 changed files with 71 additions and 58 deletions
|
@ -1,5 +1,5 @@
|
||||||
# local
|
# local
|
||||||
from .utils.project import get_project_name, list_projects
|
from .utils._misc import get_project_name, get_services, list_projects
|
||||||
|
|
||||||
# parent
|
# parent
|
||||||
from ..parser import Parser
|
from ..parser import Parser
|
||||||
|
@ -69,6 +69,8 @@ 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"""
|
||||||
|
|
||||||
def __init__(self, name, **kwargs):
|
def __init__(self, name, **kwargs):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
name, num_projects='?', num_services='*',
|
name, num_projects='?', num_services='*',
|
||||||
|
@ -84,21 +86,23 @@ class FlexCommand(ServiceCommand):
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _run_project(self, runner, config, args):
|
def _run_project(self, runner, config, args, project_name):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _run_services(self, runner, config, args):
|
def _run_services(self, runner, config, args, project_name, services):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def run(self, runner, config, args):
|
def run(self, runner, config, args):
|
||||||
if 'projects' not in args or args.projects is None:
|
project_name = get_project_name(args)
|
||||||
# command for entire instance
|
services = get_services(args)
|
||||||
|
|
||||||
|
if project_name is None:
|
||||||
|
# no project given, run for entire instance
|
||||||
return self._run_instance(runner, config, args)
|
return self._run_instance(runner, config, args)
|
||||||
|
|
||||||
elif 'services' not in args or not args.services:
|
if services is None:
|
||||||
# command for whole project
|
# no services given, run for whole project
|
||||||
return self._run_project(runner, config, args)
|
return self._run_project(runner, config, args, project_name)
|
||||||
|
|
||||||
else:
|
# run for service(s) inside project
|
||||||
# command for service(s) inside project
|
return self._run_services(runner, config, args, project_name, services)
|
||||||
return self._run_services(runner, config, args)
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import subprocess
|
||||||
|
|
||||||
# local
|
# local
|
||||||
from ._subcommand import SubCommand
|
from ._subcommand import SubCommand
|
||||||
from .utils.project 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,8 +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.project import get_project_name, list_projects
|
from .utils._misc import are_you_sure
|
||||||
from .utils.user_input import are_you_sure
|
|
||||||
|
|
||||||
|
|
||||||
class DownCommand(FlexCommand):
|
class DownCommand(FlexCommand):
|
||||||
|
@ -18,25 +17,25 @@ class DownCommand(FlexCommand):
|
||||||
|
|
||||||
def _run_instance(self, runner, config, args):
|
def _run_instance(self, runner, config, args):
|
||||||
if are_you_sure("This will bring down the entire instance."):
|
if are_you_sure("This will bring down the entire instance."):
|
||||||
super()._run_instance(runner, config, args)
|
return super()._run_instance(runner, config, args)
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _run_project(self, runner, config, args):
|
def _run_project(self, runner, config, args, project_name):
|
||||||
logging.info(f"Bringing down project '{get_project_name(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):
|
def _run_services(self, runner, config, args, project_name, services):
|
||||||
logging.info(f"Bringing down services {args.services} in project '{get_project_name(args)}'")
|
logging.info(f"Bringing down services {services} in project '{project_name}'")
|
||||||
|
|
||||||
DockerCommand('docker-compose').run(
|
DockerCommand('docker-compose').run(
|
||||||
config, args, ['stop', *args.services]
|
config, args, ['stop', *services]
|
||||||
)
|
)
|
||||||
DockerCommand('docker-compose').run(
|
DockerCommand('docker-compose').run(
|
||||||
config, args, ['rm', '-f', *args.services]
|
config, args, ['rm', '-f', *services]
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -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.user_input import are_you_sure
|
from .utils._misc import are_you_sure
|
||||||
|
|
||||||
|
|
||||||
def _find_net(config, args):
|
def _find_net(config, args):
|
||||||
|
|
|
@ -4,7 +4,6 @@ import logging
|
||||||
# local
|
# local
|
||||||
from ._subcommand import FlexCommand
|
from ._subcommand import FlexCommand
|
||||||
from .utils.dockercommand import DockerCommand
|
from .utils.dockercommand import DockerCommand
|
||||||
from .utils.project import get_project_name, list_projects
|
|
||||||
|
|
||||||
|
|
||||||
class UpCommand(FlexCommand):
|
class UpCommand(FlexCommand):
|
||||||
|
@ -15,18 +14,18 @@ class UpCommand(FlexCommand):
|
||||||
'up', description="Bring up the whole instance, a project or service(s) inside a project"
|
'up', description="Bring up the whole instance, a project or service(s) inside a project"
|
||||||
)
|
)
|
||||||
|
|
||||||
def _run_project(self, runner, config, args):
|
def _run_project(self, runner, config, args, project_name):
|
||||||
logging.info(f"Bringing up project '{get_project_name(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):
|
def _run_services(self, runner, config, args, project_name, services):
|
||||||
logging.info(f"Bringing up services {args.services} in project '{get_project_name(args)}'")
|
logging.info(f"Bringing up services {services} in project '{project_name}'")
|
||||||
|
|
||||||
DockerCommand('docker-compose').run(
|
DockerCommand('docker-compose').run(
|
||||||
config, args, ['up', '-d', *args.services]
|
config, args, ['up', '-d', *services]
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -13,6 +13,15 @@ def get_project_name(args):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def get_services(args):
|
||||||
|
"""get services list from CLI args"""
|
||||||
|
|
||||||
|
if args is not None and 'services' in args:
|
||||||
|
return args.services
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_project_dir(config, project_name):
|
def get_project_dir(config, project_name):
|
||||||
"""get project directory"""
|
"""get project directory"""
|
||||||
|
|
||||||
|
@ -41,3 +50,33 @@ def list_projects(config):
|
||||||
projects = [p[:-len(config['markers:project'])] for p in project_dirs]
|
projects = [p[:-len(config['markers:project'])] for p in project_dirs]
|
||||||
|
|
||||||
return projects
|
return projects
|
||||||
|
|
||||||
|
|
||||||
|
def _surround(string, bang):
|
||||||
|
midlane = f"{bang * 3} {string} {bang * 3}"
|
||||||
|
sidelane = bang*len(midlane)
|
||||||
|
|
||||||
|
return f"{sidelane}\n{midlane}\n{sidelane}"
|
||||||
|
|
||||||
|
|
||||||
|
def are_you_sure(prompt, default="no"):
|
||||||
|
if default.lower() == 'yes':
|
||||||
|
suffix = "[YES|no]"
|
||||||
|
else:
|
||||||
|
suffix = "[yes|NO]"
|
||||||
|
|
||||||
|
answer = input(
|
||||||
|
f"{_surround('CAREFULING IN PROGRESS', '!')}\n"
|
||||||
|
f"\n"
|
||||||
|
f">>> {prompt} <<<\n"
|
||||||
|
f"\n"
|
||||||
|
f"Are you sure you want to proceed? {suffix} "
|
||||||
|
).strip().lower()
|
||||||
|
|
||||||
|
if answer == '':
|
||||||
|
answer = default
|
||||||
|
|
||||||
|
while answer not in ['yes', 'no']:
|
||||||
|
answer = input("Please type 'yes' or 'no' explicitly: ").strip().lower()
|
||||||
|
|
||||||
|
return answer == 'yes'
|
|
@ -1,10 +1,11 @@
|
||||||
# system
|
# system
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
# local
|
# local
|
||||||
from .executable import Executable
|
from .executable import Executable
|
||||||
from .project import *
|
from ._misc import get_project_dir, get_project_name
|
||||||
|
|
||||||
# parent
|
# parent
|
||||||
from ..._constants import CONF_DIRECTORY_NAME
|
from ..._constants import CONF_DIRECTORY_NAME
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
|
|
||||||
def _surround(string, bang):
|
|
||||||
midlane = f"{bang * 3} {string} {bang * 3}"
|
|
||||||
sidelane = bang*len(midlane)
|
|
||||||
|
|
||||||
return f"{sidelane}\n{midlane}\n{sidelane}"
|
|
||||||
|
|
||||||
|
|
||||||
def are_you_sure(prompt, default="no"):
|
|
||||||
if default.lower() == 'yes':
|
|
||||||
suffix = "[YES|no]"
|
|
||||||
else:
|
|
||||||
suffix = "[yes|NO]"
|
|
||||||
|
|
||||||
answer = input(
|
|
||||||
f"{_surround('CAREFULING IN PROGRESS', '!')}\n"
|
|
||||||
f"\n"
|
|
||||||
f">>> {prompt} <<<\n"
|
|
||||||
f"\n"
|
|
||||||
f"Are you sure you want to proceed? {suffix} "
|
|
||||||
).strip().lower()
|
|
||||||
|
|
||||||
if answer == '':
|
|
||||||
answer = default
|
|
||||||
|
|
||||||
while answer not in ['yes', 'no']:
|
|
||||||
answer = input("Please type 'yes' or 'no' explicitly: ").strip().lower()
|
|
||||||
|
|
||||||
return answer == 'yes'
|
|
Loading…
Reference in a new issue