From 61cbfb40d992a631c662165f43d867bb250cc15e Mon Sep 17 00:00:00 2001 From: ldericher <40151420+ldericher@users.noreply.github.com> Date: Thu, 2 Dec 2021 19:32:38 +0100 Subject: [PATCH] projects ordering in KiwiCommand.run --- kiwi_scp/commands/cmd.py | 12 ++++-------- kiwi_scp/instance.py | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/kiwi_scp/commands/cmd.py b/kiwi_scp/commands/cmd.py index 99e3606..ed3fa9f 100644 --- a/kiwi_scp/commands/cmd.py +++ b/kiwi_scp/commands/cmd.py @@ -105,11 +105,7 @@ class KiwiCommand: _logger.debug(f"{instance.directory!r}: {project_names!r}, {service_names!r}") - projects = [ - project - for project in instance.projects - if project.name in project_names - ] + projects = instance.get_projects(project_names) if not projects: # run for whole instance @@ -118,7 +114,7 @@ class KiwiCommand: elif not service_names: # run for entire project(s) - for project_name, project in zip(project_names, projects): + for project_name, project in projects.items(): if project is None: _logger.debug(f"running for new project {project_name}, kwargs={kwargs}") cls.run_for_new_project(instance, project_name, **kwargs) @@ -133,8 +129,8 @@ class KiwiCommand: else: # run for some services - project_name = project_names[0] - project = projects[0] + project_name = list(projects)[0] + project = projects[project_name] if project is None: cls.print_error(f"Project '{project_name}' not in kiwi-scp instance at '{instance.directory}'!") diff --git a/kiwi_scp/instance.py b/kiwi_scp/instance.py index f5f63b6..30389e7 100644 --- a/kiwi_scp/instance.py +++ b/kiwi_scp/instance.py @@ -1,5 +1,5 @@ from pathlib import Path -from typing import Generator +from typing import Generator, Dict, Sequence import attr @@ -24,3 +24,19 @@ class Instance: directory=self.directory.joinpath(project.name), parent=self, ) + + def get_projects(self, project_names: Sequence[str]) -> Dict[str, Project]: + existing_projects = { + project.name: project + for project in self.projects + if project.name in project_names + } + nonexistent_projects = { + name: None + for name in project_names + if name not in existing_projects + } + return { + **existing_projects, + **nonexistent_projects + }