mirror of
https://github.com/yavook/kiwi-scp.git
synced 2024-12-25 18:42:59 +00:00
subcommands "new", "enable", "disable"
This commit is contained in:
parent
3014e7057c
commit
1a98137c71
6 changed files with 141 additions and 0 deletions
19
src/etc/docker-compose_default.yml
Normal file
19
src/etc/docker-compose_default.yml
Normal file
|
@ -0,0 +1,19 @@
|
|||
version: "2"
|
||||
|
||||
networks:
|
||||
# reachable from outside
|
||||
default:
|
||||
driver: bridge
|
||||
# interconnects projects
|
||||
kiwi_hub:
|
||||
external:
|
||||
name: $KIWI_HUB_NAME
|
||||
|
||||
services:
|
||||
something:
|
||||
image: maintainer/repo:tag
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- default
|
||||
- kiwi_hub
|
||||
[...]
|
|
@ -18,6 +18,7 @@ KIWI_CONF_NAME = os.getenv('KIWI_CONF_NAME', "kiwi.yml")
|
|||
HEADER_KIWI_CONF_NAME = f"{KIWI_ROOT}/etc/kiwi_header.yml"
|
||||
DEFAULT_KIWI_CONF_NAME = f"{KIWI_ROOT}/etc/kiwi_default.yml"
|
||||
VERSION_TAG_NAME = f"{KIWI_ROOT}/etc/version_tag"
|
||||
DEFAULT_DOCKER_COMPOSE_NAME = f"{KIWI_ROOT}/etc/docker-compose_default.yml"
|
||||
|
||||
# special config directory in projects
|
||||
CONF_DIRECTORY_NAME = 'conf'
|
||||
|
|
|
@ -2,10 +2,13 @@
|
|||
from .build import BuildCommand
|
||||
from .cmd import CmdCommand
|
||||
from .conf import ConfCopyCommand, ConfPurgeCommand
|
||||
from .disable import DisableCommand
|
||||
from .down import DownCommand
|
||||
from .enable import EnableCommand
|
||||
from .init import InitCommand
|
||||
from .logs import LogsCommand
|
||||
from .net import NetUpCommand, NetDownCommand
|
||||
from .new import NewCommand
|
||||
from .pull import PullCommand
|
||||
from .push import PushCommand
|
||||
from .sh import ShCommand
|
||||
|
@ -18,11 +21,14 @@ __all__ = [
|
|||
'CmdCommand',
|
||||
'ConfCopyCommand',
|
||||
'ConfPurgeCommand',
|
||||
'DisableCommand',
|
||||
'DownCommand',
|
||||
'EnableCommand',
|
||||
'InitCommand',
|
||||
'LogsCommand',
|
||||
'NetUpCommand',
|
||||
'NetDownCommand',
|
||||
'NewCommand',
|
||||
'PullCommand',
|
||||
'PushCommand',
|
||||
'ShCommand',
|
||||
|
|
38
src/kiwi/subcommands/disable.py
Normal file
38
src/kiwi/subcommands/disable.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
# system
|
||||
import logging
|
||||
import os
|
||||
|
||||
# local
|
||||
from .utils.misc import get_project_names, get_project_dir, get_project_down_dir
|
||||
from ._subcommand import ProjectCommand
|
||||
|
||||
|
||||
class DisableCommand(ProjectCommand):
|
||||
"""kiwi disable"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
'disable', num_projects='+',
|
||||
description="Disable whole project(s) in this instance"
|
||||
)
|
||||
|
||||
def run(self, runner, config, args):
|
||||
result = True
|
||||
|
||||
for project_name in get_project_names(args):
|
||||
project_dir = get_project_dir(config, project_name)
|
||||
project_down_dir = get_project_down_dir(config, project_name)
|
||||
|
||||
if os.path.isdir(project_dir):
|
||||
logging.info(f"Disabling project '{project_name}'")
|
||||
os.rename(project_dir, project_down_dir)
|
||||
|
||||
elif os.path.isdir(project_down_dir):
|
||||
logging.warning(f"Project '{project_name}' is already disabled!")
|
||||
result = False
|
||||
|
||||
else:
|
||||
logging.warning(f"Project '{project_name}' not found in instance!")
|
||||
result = False
|
||||
|
||||
return result
|
38
src/kiwi/subcommands/enable.py
Normal file
38
src/kiwi/subcommands/enable.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
# system
|
||||
import logging
|
||||
import os
|
||||
|
||||
# local
|
||||
from .utils.misc import get_project_names, get_project_dir, get_project_down_dir
|
||||
from ._subcommand import ProjectCommand
|
||||
|
||||
|
||||
class EnableCommand(ProjectCommand):
|
||||
"""kiwi enable"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
'enable', num_projects='+',
|
||||
description="Enable whole project(s) in this instance"
|
||||
)
|
||||
|
||||
def run(self, runner, config, args):
|
||||
result = True
|
||||
|
||||
for project_name in get_project_names(args):
|
||||
project_dir = get_project_dir(config, project_name)
|
||||
project_down_dir = get_project_down_dir(config, project_name)
|
||||
|
||||
if os.path.isdir(project_down_dir):
|
||||
logging.info(f"Enabling project '{project_name}'")
|
||||
os.rename(project_down_dir, project_dir)
|
||||
|
||||
elif os.path.isdir(project_dir):
|
||||
logging.warning(f"Project '{project_name}' is already enabled!")
|
||||
result = False
|
||||
|
||||
else:
|
||||
logging.warning(f"Project '{project_name}' not found in instance!")
|
||||
result = False
|
||||
|
||||
return result
|
39
src/kiwi/subcommands/new.py
Normal file
39
src/kiwi/subcommands/new.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
# system
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
|
||||
# local
|
||||
from .utils.misc import get_project_names, get_project_dir, get_project_down_dir
|
||||
from ._subcommand import ProjectCommand
|
||||
|
||||
# parent
|
||||
from .._constants import DEFAULT_DOCKER_COMPOSE_NAME
|
||||
|
||||
|
||||
class NewCommand(ProjectCommand):
|
||||
"""kiwi new"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
'new', num_projects='+',
|
||||
description="Create new empty project(s) in this instance"
|
||||
)
|
||||
|
||||
def run(self, runner, config, args):
|
||||
result = True
|
||||
|
||||
for project_name in get_project_names(args):
|
||||
project_dir = get_project_dir(config, project_name)
|
||||
project_down_dir = get_project_down_dir(config, project_name)
|
||||
|
||||
if os.path.isdir(project_dir) or os.path.isdir(project_down_dir):
|
||||
logging.error(f"Project '{project_name}' exists in this instance!")
|
||||
result = False
|
||||
|
||||
else:
|
||||
logging.info(f"Creating project '{project_name}'")
|
||||
os.mkdir(project_dir)
|
||||
shutil.copy(DEFAULT_DOCKER_COMPOSE_NAME, os.path.join(project_dir, "docker-compose.yml"))
|
||||
|
||||
return result
|
Loading…
Reference in a new issue