QoL: Added _run_project overridable with automatic call for multiple projects
This commit is contained in:
parent
40e476ba7b
commit
6819eabb67
7 changed files with 28 additions and 39 deletions
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
|
||||||
])
|
|
||||||
|
|
|
@ -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):
|
||||||
|
|
|
@ -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
|
|
||||||
])
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
if project.exists():
|
||||||
|
logging.error(f"Project '{project.get_name()}' exists in this instance!")
|
||||||
|
return False
|
||||||
|
|
||||||
for project in projects:
|
else:
|
||||||
if project.exists():
|
os.mkdir(project.disabled_dir_name())
|
||||||
logging.error(f"Project '{project.get_name()}' exists in this instance!")
|
shutil.copy(DEFAULT_DOCKER_COMPOSE_NAME, project.compose_file_name())
|
||||||
result = False
|
logging.debug(f"Project '{project.get_name()}' created")
|
||||||
|
return True
|
||||||
else:
|
|
||||||
logging.info(f"Creating project '{project.get_name()}'")
|
|
||||||
os.mkdir(project.disabled_dir_name())
|
|
||||||
shutil.copy(DEFAULT_DOCKER_COMPOSE_NAME, project.compose_file_name())
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
Loading…
Reference in a new issue