Skip to content

Commit

Permalink
Merge pull request #3 from nkolmar/bugfix/2-fix-delete-export-based-o…
Browse files Browse the repository at this point in the history
…n-project-name

#2 - Fix deleting / exporting projects based on project name
  • Loading branch information
reckart authored Feb 27, 2021
2 parents 5a0bf66 + 1339734 commit dad128b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion inception/commands/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions inception/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit dad128b

Please sign in to comment.