1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2024-12-24 10:13:00 +00:00

"kiwi new"

This commit is contained in:
Jörn-Michael Miehe 2022-01-20 10:21:05 +01:00
parent cd11167fda
commit ed57e09d24
3 changed files with 43 additions and 30 deletions

View file

@ -0,0 +1,39 @@
import os
import shutil
import click
from .cmd import KiwiCommandType, KiwiCommand
from .decorators import kiwi_command
from .._constants import DEFAULT_DOCKER_COMPOSE_NAME, COMPOSE_FILE_NAME
from ..config import ProjectConfig
from ..instance import Instance
from ..project import Project
@kiwi_command()
class NewCommand(KiwiCommand):
"""Create new empty project(s) in this instance"""
type = KiwiCommandType.PROJECTS
@classmethod
def run_for_project(cls, instance: Instance, project: Project, **kwargs) -> None:
KiwiCommand.print_error(f"Project {project.name} already exists!")
@classmethod
def run_for_new_project(cls, instance: Instance, project_name: str, **kwargs) -> None:
try:
os.mkdir(project_name)
instance.config.projects.append(ProjectConfig(
name=project_name,
enabled=False,
))
shutil.copy(
DEFAULT_DOCKER_COMPOSE_NAME,
instance.directory.joinpath(project_name).joinpath(COMPOSE_FILE_NAME)
)
instance.save_config(instance.config)
except FileExistsError:
KiwiCommand.print_error(f"Project directory {project_name} already exists!")

View file

@ -10,6 +10,10 @@ networks:
name: ${KIWI_HUB_NAME}
services:
######################
# START EDITING HERE #
######################
# an example service
something:
# uses an image

View file

@ -1,30 +0,0 @@
# system
import logging
import os
import shutil
# local
from .._constants import DEFAULT_DOCKER_COMPOSE_NAME
from ..subcommand import ProjectCommand
class NewCommand(ProjectCommand):
"""kiwi new"""
def __init__(self):
super().__init__(
'new', num_projects='+',
action="Creating",
description="Create new empty project(s) in this instance"
)
def _run_project(self, runner, args, project):
if project.exists():
logging.error(f"Project '{project.get_name()}' exists in this instance!")
return False
else:
os.mkdir(project.disabled_dir_name())
shutil.copy(DEFAULT_DOCKER_COMPOSE_NAME, project.compose_file_name())
logging.debug(f"Project '{project.get_name()}' created")
return True