From 1339734c60488f4307ce9046a9936e9c0f3a23b4 Mon Sep 17 00:00:00 2001 From: Nina Kolmar Date: Tue, 23 Feb 2021 12:02:32 +0100 Subject: [PATCH] #2 - Fix deleting / exporting projects based on project name --- inception/commands/project.py | 6 +++++- inception/utils.py | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/inception/commands/project.py b/inception/commands/project.py index 29e0710..773621f 100644 --- a/inception/commands/project.py +++ b/inception/commands/project.py @@ -7,7 +7,7 @@ import click -from inception.utils import make_client, list_matching_projects +from inception.utils import make_client, list_matching_projects, get_project_from_name _log = logging.getLogger("inception") @@ -28,6 +28,8 @@ def export_projects(url: str, user: Optional[str], regex: bool, dry_run: bool, o if regex: projects = list_matching_projects(client, projects) + else: + projects = get_project_from_name(client, projects[0]) target_folder = Path(out) target_folder.mkdir(parents=True, exist_ok=True) @@ -87,6 +89,8 @@ def delete_project(url: str, user: Optional[str], regex: bool, dry_run: bool, pr if regex: projects = list_matching_projects(client, projects) + else: + projects = get_project_from_name(client, projects[0]) for project in projects: _log.info("Deleting [%s]", project.project_name) diff --git a/inception/utils.py b/inception/utils.py index 70e5506..3d3cb24 100644 --- a/inception/utils.py +++ b/inception/utils.py @@ -28,3 +28,17 @@ def list_matching_projects(client: Pycaprio, patterns: List[str]) -> List[str]: projects.append(accessible_project) return projects + + +def get_project_from_name(client: Pycaprio, name: str) -> List[str]: + """ + Scans the server for any projects matching the given name and returns the corresponding project. + """ + + projects = [] + accessible_projects = client.api.projects() + for accessible_project in accessible_projects: + if name == accessible_project.project_name: + projects.append(accessible_project) + + return projects