2020-08-18 13:56:58 +00:00
|
|
|
# system
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
|
|
|
|
# local
|
|
|
|
from .._constants import DEFAULT_DOCKER_COMPOSE_NAME
|
2020-08-19 15:21:38 +00:00
|
|
|
from ..subcommand import ProjectCommand
|
2020-08-18 13:56:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
class NewCommand(ProjectCommand):
|
|
|
|
"""kiwi new"""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__(
|
|
|
|
'new', num_projects='+',
|
2020-08-19 14:10:56 +00:00
|
|
|
action="Creating",
|
2020-08-18 13:56:58 +00:00
|
|
|
description="Create new empty project(s) in this instance"
|
|
|
|
)
|
|
|
|
|
2020-08-19 14:10:56 +00:00
|
|
|
def _run_projects(self, runner, args, projects):
|
2020-08-18 13:56:58 +00:00
|
|
|
result = True
|
|
|
|
|
2020-08-19 09:58:13 +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:
|
2020-08-19 09:58:13 +00:00
|
|
|
logging.info(f"Creating project '{project.get_name()}'")
|
2020-08-19 14:10:56 +00:00
|
|
|
os.mkdir(project.disabled_dir_name())
|
2020-08-19 09:58:13 +00:00
|
|
|
shutil.copy(DEFAULT_DOCKER_COMPOSE_NAME, project.compose_file_name())
|
2020-08-18 13:56:58 +00:00
|
|
|
|
|
|
|
return result
|