1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2024-11-22 21:03:00 +00:00
kiwi-scp/src/kiwi/subcommands/new.py

38 lines
970 B
Python
Raw Normal View History

2020-08-18 13:56:58 +00:00
# system
import logging
import os
import shutil
# local
from .utils.project import Projects
2020-08-18 13:56:58 +00:00
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
projects = Projects.from_args(args)
2020-08-18 13:56:58 +00:00
for project in projects:
if project.exists():
logging.error(f"Project '{project.get_name()}' exists in this instance!")
2020-08-18 13:56:58 +00:00
result = False
else:
logging.info(f"Creating project '{project.get_name()}'")
os.mkdir(project.enabled_dir_name())
shutil.copy(DEFAULT_DOCKER_COMPOSE_NAME, project.compose_file_name())
2020-08-18 13:56:58 +00:00
return result