From 887d92692066288f774203832c9b3ee7cbe24b4a Mon Sep 17 00:00:00 2001 From: Till Hartmann Date: Fri, 6 Sep 2024 13:05:24 +0200 Subject: [PATCH 1/5] feat: add --filter-status option for controlling which landing zones are listed --- src/cubi_tk/sodar/lz_list.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/cubi_tk/sodar/lz_list.py b/src/cubi_tk/sodar/lz_list.py index cddf421c..35fa0d16 100644 --- a/src/cubi_tk/sodar/lz_list.py +++ b/src/cubi_tk/sodar/lz_list.py @@ -62,6 +62,14 @@ def setup_argparse(cls, parser: argparse.ArgumentParser) -> None: help="Format string for printing, e.g. %%(uuid)s", ) + parser.add_argument( + "--filter-status", + dest="filter_status", + default=[], + action='append', + help="Filter landing zones by status, e.g. ACTIVE, FAILED", + ) + parser.add_argument("project_uuid", help="UUID of project to create the landing zone in.") @classmethod @@ -101,7 +109,7 @@ def execute(self) -> typing.Optional[int]: key=lambda lz: lz.date_modified, ) for lz in existing_lzs: - if lz.status != "ACTIVE": + if lz.status in self.args.filter_status: continue values = cattr.unstructure(lz) if self.args.format_string: From bcc28a29f6c316d2aada2eea1f4fd9c62082747b Mon Sep 17 00:00:00 2001 From: Till Hartmann Date: Fri, 6 Sep 2024 13:10:02 +0200 Subject: [PATCH 2/5] restrict choices --- src/cubi_tk/sodar/lz_list.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cubi_tk/sodar/lz_list.py b/src/cubi_tk/sodar/lz_list.py index 35fa0d16..32cdd411 100644 --- a/src/cubi_tk/sodar/lz_list.py +++ b/src/cubi_tk/sodar/lz_list.py @@ -65,9 +65,10 @@ def setup_argparse(cls, parser: argparse.ArgumentParser) -> None: parser.add_argument( "--filter-status", dest="filter_status", - default=[], - action='append', - help="Filter landing zones by status, e.g. ACTIVE, FAILED", + default=set(), + action="append", + choices=["ACTIVE", "FAILED", "VALIDATING"], + help="Filter landing zones by status", ) parser.add_argument("project_uuid", help="UUID of project to create the landing zone in.") From 1d0e00668e7dbbc96d3b14e08b555311e6152d18 Mon Sep 17 00:00:00 2001 From: Till Hartmann Date: Fri, 6 Sep 2024 13:10:40 +0200 Subject: [PATCH 3/5] fix typo --- src/cubi_tk/sodar/lz_list.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cubi_tk/sodar/lz_list.py b/src/cubi_tk/sodar/lz_list.py index 32cdd411..0790124b 100644 --- a/src/cubi_tk/sodar/lz_list.py +++ b/src/cubi_tk/sodar/lz_list.py @@ -68,7 +68,7 @@ def setup_argparse(cls, parser: argparse.ArgumentParser) -> None: default=set(), action="append", choices=["ACTIVE", "FAILED", "VALIDATING"], - help="Filter landing zones by status", + help="Filter landing zone by status", ) parser.add_argument("project_uuid", help="UUID of project to create the landing zone in.") From 0a8ce1ed0d8c234f496f4cafa89daa7501cce7c7 Mon Sep 17 00:00:00 2001 From: Till Hartmann Date: Fri, 6 Sep 2024 17:00:29 +0200 Subject: [PATCH 4/5] reverse logic --- src/cubi_tk/sodar/lz_list.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cubi_tk/sodar/lz_list.py b/src/cubi_tk/sodar/lz_list.py index 0790124b..20d6d9d0 100644 --- a/src/cubi_tk/sodar/lz_list.py +++ b/src/cubi_tk/sodar/lz_list.py @@ -62,13 +62,14 @@ def setup_argparse(cls, parser: argparse.ArgumentParser) -> None: help="Format string for printing, e.g. %%(uuid)s", ) + status = ["ACTIVE", "FAILED", "VALIDATING"] parser.add_argument( "--filter-status", dest="filter_status", - default=set(), + default=set(status), action="append", - choices=["ACTIVE", "FAILED", "VALIDATING"], - help="Filter landing zone by status", + choices=status, + help="Filter landing zone by status. Defaults to listing all.", ) parser.add_argument("project_uuid", help="UUID of project to create the landing zone in.") @@ -110,7 +111,7 @@ def execute(self) -> typing.Optional[int]: key=lambda lz: lz.date_modified, ) for lz in existing_lzs: - if lz.status in self.args.filter_status: + if lz.status not in self.args.filter_status: continue values = cattr.unstructure(lz) if self.args.format_string: From bd6eb348a4961e6773445f32c64e64844b6f1ac5 Mon Sep 17 00:00:00 2001 From: Till Hartmann Date: Tue, 14 Jan 2025 12:06:31 +0100 Subject: [PATCH 5/5] extract local status var to module level LANDING_ZONE_STATES --- src/cubi_tk/sodar/lz_list.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cubi_tk/sodar/lz_list.py b/src/cubi_tk/sodar/lz_list.py index 20d6d9d0..b92519a2 100644 --- a/src/cubi_tk/sodar/lz_list.py +++ b/src/cubi_tk/sodar/lz_list.py @@ -12,6 +12,9 @@ from ..common import load_toml_config +# TODO: Obtain from somewhere else, e.g. sodar-cli or sodar API or sodar-core or … +LANDING_ZONE_STATES = ["ACTIVE", "FAILED", "VALIDATING"] + class ListLandingZoneCommand: """Implementation of the ``landing-zone-list`` command.""" @@ -62,13 +65,12 @@ def setup_argparse(cls, parser: argparse.ArgumentParser) -> None: help="Format string for printing, e.g. %%(uuid)s", ) - status = ["ACTIVE", "FAILED", "VALIDATING"] parser.add_argument( "--filter-status", dest="filter_status", - default=set(status), + default=LANDING_ZONE_STATES, action="append", - choices=status, + choices=LANDING_ZONE_STATES, help="Filter landing zone by status. Defaults to listing all.", )