From 9ed47aedeed034065f6e4367d0f2c297ac39a1b2 Mon Sep 17 00:00:00 2001 From: Amin Jamal Date: Thu, 17 Jun 2021 18:42:36 +0200 Subject: [PATCH 1/3] fix bug in retriving available versions --- paxexpress_cli/cli.py | 2 ++ paxexpress_cli/files/core.py | 11 +++--- paxexpress_cli/versions/cli.py | 15 ++++++++ paxexpress_cli/versions/core.py | 58 +++++++++++++++++++++++++++---- paxexpress_cli/versions/models.py | 11 ++++++ 5 files changed, 85 insertions(+), 12 deletions(-) diff --git a/paxexpress_cli/cli.py b/paxexpress_cli/cli.py index 33ae21f..ca01f7c 100644 --- a/paxexpress_cli/cli.py +++ b/paxexpress_cli/cli.py @@ -50,8 +50,10 @@ def version(): cli.add_typer(self_cli, name="self") + def main(): cli() + if __name__ == "__main__": cli() diff --git a/paxexpress_cli/files/core.py b/paxexpress_cli/files/core.py index 1cc201c..b97f0ef 100644 --- a/paxexpress_cli/files/core.py +++ b/paxexpress_cli/files/core.py @@ -14,6 +14,7 @@ import typer from paxexpress_cli.packages import core as packages_core from paxexpress_cli.repositories import core as repositories +from paxexpress_cli.versions import core as versions_core def get_versions_file( @@ -54,8 +55,8 @@ def get_package_file( subject=subject, repo=repo ) if not version: - version = select_from_available_versions( - subject=subject, repo=repo, package=package, filename=None + version = versions_core.select_from_available_versions( + subject=subject, repo=repo, package=package ) url = get_url(f"/packages/{subject}/{repo}/{package}/versions/{version}/files") params = {} @@ -139,7 +140,7 @@ def file_download( subject=subject, repo=repo ) if not version: - version = select_from_available_versions( + version = select_from_available_versions_by_filename( subject=subject, repo=repo, package=package, filename=file_name ) @@ -158,7 +159,7 @@ def file_download( print_error(response.text) -def select_from_available_versions( +def select_from_available_versions_by_filename( subject: str, repo: str, package: str, filename: Optional[str] ) -> Optional[str]: files = get_versions_file( @@ -223,7 +224,7 @@ def delete_file( subject=username, repo=repo ) if not version: - version = select_from_available_versions( + version = select_from_available_versions_by_filename( subject=username, repo=repo, package=package, filename=filename ) diff --git a/paxexpress_cli/versions/cli.py b/paxexpress_cli/versions/cli.py index 1401c0a..a825e31 100644 --- a/paxexpress_cli/versions/cli.py +++ b/paxexpress_cli/versions/cli.py @@ -7,6 +7,7 @@ delete_version, update_version, get_version_for_file, + get_packages_available_versions, ) version_cli = Typer(name="version") @@ -53,6 +54,20 @@ def get( ) +@version_cli.command(name="available", help="Get available version") +def get_available( + subject: str = Option(..., "-s", "--subject"), + repo: str = Option(None, "-r", "--repo"), + package: str = Option(None, "-p", "--package"), +): + + get_packages_available_versions( + subject=subject, + repo=repo, + package=package, + ) + + @version_cli.command(name="create", help="Create a version") def create( repo: str = Option(None, "-r", "--repo"), diff --git a/paxexpress_cli/versions/core.py b/paxexpress_cli/versions/core.py index a1e56db..3dc386d 100644 --- a/paxexpress_cli/versions/core.py +++ b/paxexpress_cli/versions/core.py @@ -1,6 +1,8 @@ +from paxexpress_cli.utils import print_error, select_available_options from typing import Optional import httpx from .models import ( + VersionGetAvailableVersionResponseModel, VersionModel, VersionCreateBodyModel, VersionUpdateBodyModel, @@ -15,7 +17,28 @@ from ..authentication.core import get_auth_header_and_username from paxexpress_cli.repositories import core as repositories_core from paxexpress_cli.packages import core as packages_core -from paxexpress_cli.files import core as files_core + + +def select_from_available_versions( + subject: str, repo: str, package: str +) -> Optional[str]: + from paxexpress_cli.versions.core import get_packages_available_versions + + versions = get_packages_available_versions( + subject=subject, package=package, repo=repo, is_internal=True + ) + if not versions: + print_error("No versions have been created!") + exit(1) + selected_version = select_available_options( + name="version", + message="Select the version", + choices=[item["name"] for item in versions], + ) + if not selected_version: + print_error("No version has been selected!") + exit(1) + return selected_version["version"] def get_latest( @@ -38,6 +61,25 @@ def get_latest( return response_handler(response=response, return_model=VersionModel) +def get_packages_available_versions( + subject: str, repo: Optional[str], package: Optional[str], is_internal: bool = False +): + if not repo: + repo = repositories_core.select_from_available_repo(subject=subject) + if not package: + package = packages_core.select_from_available_packages( + subject=subject, repo=repo + ) + + url = get_url(f"/packages/{subject}/{repo}/{package}/versions/available") + response = httpx.get(url=url) + if is_internal: + return response_handler( + response=response, return_with_out_model=True, print_result=False + ) + response_handler(response=response) + + def get_version( subject: str, repo: Optional[str], @@ -52,8 +94,8 @@ def get_version( subject=subject, repo=repo ) if not version: - version = files_core.select_from_available_versions( - subject=subject, repo=repo, package=package, filename=None + version = select_from_available_versions( + subject=subject, repo=repo, package=package ) url = get_url(f"/packages/{subject}/{repo}/{package}/versions/{version}") params = {"attribute_values": attribute_values} @@ -93,8 +135,10 @@ def delete_version( subject=username, repo=repo ) if not version: - version = files_core.select_from_available_versions( - subject=username, repo=repo, package=package, filename=None + version = select_from_available_versions( + subject=username, + repo=repo, + package=package, ) if not is_operation_confirmed and not is_operation_confirm(): return @@ -119,8 +163,8 @@ def update_version( subject=username, repo=repo ) if not version: - version = files_core.select_from_available_versions( - subject=username, repo=repo, package=package, filename=None + version = select_from_available_versions( + subject=username, repo=repo, package=package ) body = pydantic_to_prompt(model=VersionUpdateBodyModel) if not is_operation_confirmed and not is_operation_confirm(): diff --git a/paxexpress_cli/versions/models.py b/paxexpress_cli/versions/models.py index f513229..3f8c9d9 100644 --- a/paxexpress_cli/versions/models.py +++ b/paxexpress_cli/versions/models.py @@ -58,6 +58,17 @@ class VersionGetResponseModel(VersionModel): pass +class VersionSummeryModel(BaseModel): + name: str + repo: Optional[str] + package: Optional[str] + owner: str + + +class VersionGetAvailableVersionResponseModel(BaseModel): + __root__: List[VersionSummeryModel] = [] + + class VersionCreateBodyModel(BaseModel): name: str # released: Optional[str] From eac607f793ef7bdfe67441cdaeaefce1618111ce Mon Sep 17 00:00:00 2001 From: Amin Jamal Date: Thu, 24 Jun 2021 13:16:01 +0200 Subject: [PATCH 2/3] update VersionSummaryModel --- paxexpress_cli/versions/models.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/paxexpress_cli/versions/models.py b/paxexpress_cli/versions/models.py index 3f8c9d9..1911af1 100644 --- a/paxexpress_cli/versions/models.py +++ b/paxexpress_cli/versions/models.py @@ -58,15 +58,16 @@ class VersionGetResponseModel(VersionModel): pass -class VersionSummeryModel(BaseModel): +class VersionSummaryModel(BaseModel): name: str repo: Optional[str] package: Optional[str] owner: str + released: Optional[datetime.datetime] class VersionGetAvailableVersionResponseModel(BaseModel): - __root__: List[VersionSummeryModel] = [] + __root__: List[VersionSummaryModel] = [] class VersionCreateBodyModel(BaseModel): From ad2665b7f5c52b9c394285b5fb289e57f0920714 Mon Sep 17 00:00:00 2001 From: Amin Jamal Date: Fri, 25 Jun 2021 09:42:13 +0200 Subject: [PATCH 3/3] remove bad import from get_packages_available_versions --- paxexpress_cli/versions/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/paxexpress_cli/versions/core.py b/paxexpress_cli/versions/core.py index 3dc386d..c4fb0c0 100644 --- a/paxexpress_cli/versions/core.py +++ b/paxexpress_cli/versions/core.py @@ -1,4 +1,3 @@ -from paxexpress_cli.utils import print_error, select_available_options from typing import Optional import httpx from .models import ( @@ -13,6 +12,8 @@ response_handler, pydantic_to_prompt, is_operation_confirm, + print_error, + select_available_options ) from ..authentication.core import get_auth_header_and_username from paxexpress_cli.repositories import core as repositories_core @@ -22,7 +23,6 @@ def select_from_available_versions( subject: str, repo: str, package: str ) -> Optional[str]: - from paxexpress_cli.versions.core import get_packages_available_versions versions = get_packages_available_versions( subject=subject, package=package, repo=repo, is_internal=True