From 73721ec44168aa332b7574d1a7c4b69cb157b9fa Mon Sep 17 00:00:00 2001 From: tcezard Date: Wed, 22 May 2024 13:22:59 +0100 Subject: [PATCH] Support multiple status --- .../release_metadata.py | 26 ++++++++++++++----- .../run_release_for_species.py | 10 ++++--- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/eva-accession-release-automation/run_release_in_embassy/release_metadata.py b/eva-accession-release-automation/run_release_in_embassy/release_metadata.py index ad7e01721..a2cef71fd 100644 --- a/eva-accession-release-automation/run_release_in_embassy/release_metadata.py +++ b/eva-accession-release-automation/run_release_in_embassy/release_metadata.py @@ -92,11 +92,23 @@ def get_release_inventory_info_for_assembly(taxonomy_id, assembly_accession, rel return results[0][0] -def get_release_pending(release_species_inventory_table, metadata_connection_handle): - results = get_all_results_for_query(metadata_connection_handle, - "select taxonomy, assembly_accession, release_version from {0} " - "where should_be_released " - "and num_rs_to_release > 0" - "ORDER BY release_version, taxonomy, assembly_accession" - .format(release_species_inventory_table)) +def get_release_pending(release_species_inventory_table, metadata_connection_handle, status=None): + def format_status(status_list): + return f"({str(status_list).strip('[]')})" + + if 'Pending' in status: + status.remove('Pending') + if status: + status_statement = f"and (release_status in {format_status(status)} or release_status is null)" + else: + status_statement = f"and release_status is null" + else: + status_statement = f"and release_status in {format_status(status)}" + + query = (f"select taxonomy, assembly_accession, release_version from {release_species_inventory_table} " + "where should_be_released " + "and num_rs_to_release > 0 " + f"{status_statement}" if status_statement else '' + "ORDER BY release_version, taxonomy, assembly_accession") + results = get_all_results_for_query(metadata_connection_handle, query) yield results diff --git a/eva-accession-release-automation/run_release_in_embassy/run_release_for_species.py b/eva-accession-release-automation/run_release_in_embassy/run_release_for_species.py index 7ef98694f..c4539aaea 100644 --- a/eva-accession-release-automation/run_release_in_embassy/run_release_for_species.py +++ b/eva-accession-release-automation/run_release_in_embassy/run_release_for_species.py @@ -106,7 +106,7 @@ def run_release_for_species(taxonomy_id, release_assemblies, release_version, re run_command_with_output(f"Running workflow file {workflow_file_path}", workflow_command) -def list_pending_release(): +def list_pending_release(status): private_config_xml_file = cfg.query("maven", "settings_file") profile = cfg.query("maven", "environment") release_species_inventory_table = cfg.query('release', 'inventory_table') @@ -114,7 +114,7 @@ def list_pending_release(): header = ['taxonomy', 'assembly_accession', 'release_version'] table = [] for taxonomy, assembly_accession, release_version in get_release_pending(release_species_inventory_table, - metadata_connection_handle): + metadata_connection_handle, status): table.append((taxonomy, assembly_accession, release_version)) pretty_print(header, table) @@ -129,7 +129,9 @@ def load_config(*args): def main(): argparse = ArgumentParser() - argparse.add_argument("--list", help="Generate the list of species and assembly that needs to be released", action='store_true', default=False) + argparse.add_argument("--list", nargs='+', + help="Generate the list of species and assembly that needs to be released", + choices=['Pending', 'Started', 'Completed']) argparse.add_argument("--taxonomy_id", help="ex: 9913", required=True) argparse.add_argument("--assembly_accessions", nargs='+', help="ex: GCA_000003055.3") argparse.add_argument("--release_version", required=True) @@ -139,7 +141,7 @@ def main(): load_config() logging_config.add_stdout_handler() if args.list: - list_pending_release() + list_pending_release(args.list) else: run_release_for_species(args.taxonomy_id, args.assembly_accessions, args.release_version, args.resume)