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

QoL: Added _run_project overridable with automatic call for multiple projects

This commit is contained in:
Jörn-Michael Miehe 2020-08-20 15:09:15 +02:00
parent 40e476ba7b
commit 6819eabb67
7 changed files with 28 additions and 39 deletions

View file

@ -65,6 +65,13 @@ class ProjectCommand(SubCommand):
return self._run_projects(runner, args, Projects.from_dir().filter_enabled()) return self._run_projects(runner, args, Projects.from_dir().filter_enabled())
def _run_projects(self, runner, args, projects): def _run_projects(self, runner, args, projects):
# default: run for all given projects
return all([
self._run_project(runner, args, project)
for project in projects
])
def _run_project(self, runner, args, project):
pass pass
def run(self, runner, args): def run(self, runner, args):
@ -102,14 +109,9 @@ class ServiceCommand(ProjectCommand):
help=f"select {services} in a project" help=f"select {services} in a project"
) )
def _run_projects(self, runner, args, projects): def _run_project(self, runner, args, project):
result = True # default: run with empty service list
return self._run_services(runner, args, project, [])
# default: run without services for all given
for project in projects:
result &= self._run_services(runner, args, project, [])
return result
def _run_services(self, runner, args, project, services): def _run_services(self, runner, args, project, services):
pass pass

View file

@ -27,7 +27,7 @@ class CmdCommand(ProjectCommand):
help="arguments for 'docker-compose' commands" help="arguments for 'docker-compose' commands"
) )
def _run_projects(self, runner, args, projects): def _run_project(self, runner, args, project):
if args.unknowns: if args.unknowns:
args.compose_args = [*args.compose_args, *args.unknowns] args.compose_args = [*args.compose_args, *args.unknowns]
args.unknowns = [] args.unknowns = []
@ -35,6 +35,6 @@ class CmdCommand(ProjectCommand):
logging.debug(f"Updated args: {args}") logging.debug(f"Updated args: {args}")
# run with split compose_cmd argument # run with split compose_cmd argument
projects[0].compose_run([args.compose_cmd, *args.compose_args]) project.compose_run([args.compose_cmd, *args.compose_args])
return True return True

View file

@ -12,8 +12,5 @@ class DisableCommand(ProjectCommand):
description="Disable project(s) in this instance" description="Disable project(s) in this instance"
) )
def _run_projects(self, runner, args, projects): def _run_project(self, runner, args, project):
return all([ return project.disable()
project.disable()
for project in projects
])

View file

@ -24,10 +24,8 @@ class DownCommand(ServiceCommand):
return False return False
def _run_projects(self, runner, args, projects): def _run_project(self, runner, args, project):
for project in projects:
project.compose_run(['down']) project.compose_run(['down'])
return True return True
def _run_services(self, runner, args, project, services): def _run_services(self, runner, args, project, services):

View file

@ -12,8 +12,5 @@ class EnableCommand(ProjectCommand):
description="Enable project(s) in this instance" description="Enable project(s) in this instance"
) )
def _run_projects(self, runner, args, projects): def _run_project(self, runner, args, project):
return all([ return project.enable()
project.enable()
for project in projects
])

View file

@ -51,8 +51,7 @@ class InspectCommand(ServiceCommand):
return True return True
def _run_projects(self, runner, args, projects): def _run_project(self, runner, args, project):
project = projects[0]
if not project.exists(): if not project.exists():
logging.warning(f"Project '{project.get_name()}' not found") logging.warning(f"Project '{project.get_name()}' not found")
return False return False

View file

@ -18,17 +18,13 @@ class NewCommand(ProjectCommand):
description="Create new empty project(s) in this instance" description="Create new empty project(s) in this instance"
) )
def _run_projects(self, runner, args, projects): def _run_project(self, runner, args, project):
result = True
for project in projects:
if project.exists(): if project.exists():
logging.error(f"Project '{project.get_name()}' exists in this instance!") logging.error(f"Project '{project.get_name()}' exists in this instance!")
result = False return False
else: else:
logging.info(f"Creating project '{project.get_name()}'")
os.mkdir(project.disabled_dir_name()) os.mkdir(project.disabled_dir_name())
shutil.copy(DEFAULT_DOCKER_COMPOSE_NAME, project.compose_file_name()) shutil.copy(DEFAULT_DOCKER_COMPOSE_NAME, project.compose_file_name())
logging.debug(f"Project '{project.get_name()}' created")
return result return True