"""
SCU Maid
Set up a SCU transfer config file, including retrieving the appropriate Jira ticket, establishing user ID, etc
"""
import click
import json
from zcloud import available_defaults
from zcloud.generic_scu_transfer import config_from_path,merge_jira_and_config
from zcloud.network_requests import get_jira_ticket_from_gcp_service
[docs]
def write_config_file (config_dict,output_path):
with open(output_path, "w") as f:
f.write(json.dumps(config_dict))
[docs]
def validate_project_data():
pass
@click.command()
@click.argument("jira_ticket_ref", type=click.STRING,required=False)
@click.option("--template-config-file","-f","config_file", type=click.Path(exists=True),required=False)
@click.option("--project","-p", type=click.STRING,required=False)
@click.option("--subproject","-s", type=click.STRING,required=False)
@click.option("--experiment","-e", type=click.STRING,required=False)
@click.option("--authors","-a", type=click.STRING,required=False)
@click.option("--bucket","-b", type=click.STRING,required=False)
@click.option("--gcp-project","-g", type=click.STRING,required=False)
@click.option("--dry-run", default=False,is_flag=True)
@click.option("--output-path","-o", type=click.Path(),required=False,default="scu_transfer_config.json")
def main(jira_ticket_ref: str, config_file: str, project: str, subproject: str, experiment: str, authors: str, bucket: str, gcp_project: str,dry_run:bool,output_path:str) -> None:
"""
Set up a SCU transfer config file, including retrieving the appropriate Jira ticket, establishing user ID, etc
Parameters
----------
jira_ticket_ref : str
The Jira ticket reference for the SCU transfer
config_file : str
The path to the configuration file to use as a template
CLI args override the config file if both are provided.
project : str
The project name
subproject : str
The subproject name
experiment : str
The experiment name
authors : str
Comma-separated list of authors
bucket : str
The GCP bucket name
gcp_project : str
The GCP project name
dry_run : bool
Whether to execute a dry run
output_path : str
The path to write the config file to
Returns
-------
None
"""
if dry_run:
raise NotImplementedError("Dry run not yet implemented")
ticket_dict = get_jira_ticket_from_gcp_service(jira_ticket_ref) # returns the ticket as a dictionary
# Parse authors into a list
if authors is not None:
authors_list = authors.split(",")
else:
authors_list = None
### Actually maybe hide this all in config_from_path #######
config_dict = config_from_path(config_file)
config_dict = merge_jira_and_config(config_dict, ticket_dict) # validates config file values against the ticket.
# Ticket overrides config file when blank, but raises an error if a conflict appears
# Override config dict with CLI args if provided
defaults = available_defaults()
args = {
"project": project,
"subproject": subproject,
"experiment": experiment,
"authors": authors_list,
"bucket": bucket,
"gcp_project": gcp_project,
}
for arg, value in args.items():
if value is not None:
config_dict[arg] = value
elif arg in defaults:
config_dict[arg] = defaults[arg]
elif config_dict.get(arg) is None:
raise ValueError(f"Required argument {arg} is missing from config file and CLI args")
###########################################################
validate_project_data()
# Write the config file
write_config_file(config_dict,output_path)
if __name__ == "__main__":
main()