From 1d4690eb36e2c702097631d3522942250d4437f3 Mon Sep 17 00:00:00 2001 From: Tom Close Date: Fri, 15 Mar 2024 10:46:34 +1100 Subject: [PATCH] fiddling with click types --- xnat_ingest/cli/stage.py | 19 ++++++++++--------- xnat_ingest/cli/transfer.py | 17 ++++++++--------- xnat_ingest/cli/upload.py | 6 +++--- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/xnat_ingest/cli/stage.py b/xnat_ingest/cli/stage.py index 6ff6547..26968ad 100644 --- a/xnat_ingest/cli/stage.py +++ b/xnat_ingest/cli/stage.py @@ -60,23 +60,23 @@ ) @click.option( "--associated-files", - type=AssociatedFiles(), + type=AssociatedFiles, nargs=2, default=None, envvar="XNAT_INGEST_ASSOCIATED", metavar=" ", help=( - "The \"glob\" arg is a glob pattern by which to detect associated files to be " + 'The "glob" arg is a glob pattern by which to detect associated files to be ' "attached to the DICOM sessions. Note that when this pattern corresponds to a " "relative path it is considered to be relative to the parent directory containing " "the DICOMs for the session NOT the current working directory Can contain string " "templates corresponding to DICOM metadata fields, which are substituted before " "the glob is called. For example, " - '"./associated/{PatientName.given_name}_{PatientName.family_name}/*)\" ' + '"./associated/{PatientName.given_name}_{PatientName.family_name}/*)" ' "will find all files under the subdirectory within '/path/to/dicoms/associated' that matches " "_. Will be interpreted as being relative to `dicoms_dir` " "if a relative path is provided.\n" - "The \"id-pattern\" arg is a regular expression that is used to extract the scan ID & " + 'The "id-pattern" arg is a regular expression that is used to extract the scan ID & ' "type/resource from the associated filename. Should be a regular-expression " "(Python syntax) with named groups called 'id' and 'type', e.g. " r"--assoc-id-pattern '[^\.]+\.[^\.]+\.(?P\d+)\.(?P\w+)\..*'" @@ -98,7 +98,7 @@ @click.option( "--log-file", default=None, - type=LogFile(), + type=LogFile, nargs=2, metavar=" ", envvar="XNAT_INGEST_LOGFILE", @@ -110,7 +110,7 @@ @click.option( "--log-email", "log_emails", - type=LogEmail(), + type=LogEmail, nargs=3, metavar="
", multiple=True, @@ -122,7 +122,7 @@ ) @click.option( "--mail-server", - type=MailServer(), + type=MailServer, nargs=4, metavar=" ", default=None, @@ -142,7 +142,7 @@ "--deidentify/--dont-deidentify", default=False, type=bool, - help="whether to deidentify the file names and DICOM metadata before staging" + help="whether to deidentify the file names and DICOM metadata before staging", ) def stage( dicoms_path: str, @@ -193,7 +193,8 @@ def stage( continue # Identify theDeidentify files if necessary and save them to the staging directory session.stage( - staging_dir, associated_files=associated_files, + staging_dir, + associated_files=associated_files, remove_original=delete, deidentify=deidentify, ) diff --git a/xnat_ingest/cli/transfer.py b/xnat_ingest/cli/transfer.py index 2f22401..2b5af3b 100644 --- a/xnat_ingest/cli/transfer.py +++ b/xnat_ingest/cli/transfer.py @@ -82,7 +82,7 @@ def remove_old_files_on_ssh(remote_store: str, threshold: int): @click.argument("remote_store", type=str, envvar="XNAT_INGEST_REMOTE_STORE") @click.option( "--store-credentials", - type=str, + type=click.Path(path_type=Path), metavar=" ", envvar="XNAT_INGEST_STORE_CREDENTIALS", default=None, @@ -99,7 +99,7 @@ def remove_old_files_on_ssh(remote_store: str, threshold: int): @click.option( "--log-file", default=None, - type=LogFile(), + type=LogFile, nargs=2, metavar=" ", envvar="XNAT_INGEST_LOGFILE", @@ -111,7 +111,7 @@ def remove_old_files_on_ssh(remote_store: str, threshold: int): @click.option( "--log-email", "log_emails", - type=LogEmail(), + type=LogEmail, nargs=3, metavar="
", multiple=True, @@ -123,7 +123,7 @@ def remove_old_files_on_ssh(remote_store: str, threshold: int): ) @click.option( "--mail-server", - type=MailServer(), + type=MailServer, metavar=" ", default=None, envvar="XNAT_INGEST_MAILSERVER", @@ -161,20 +161,19 @@ def remove_old_files_on_ssh(remote_store: str, threshold: int): help="The number of days to keep files in the remote store for", ) def transfer( - staging_dir: str, + staging_dir: Path, remote_store: str, credentials: ty.Tuple[str, str], - log_file: ty.Tuple[str, str], + log_file: LogFile, log_level: str, - log_emails: ty.List[ty.Tuple[str, str, str]], - mail_server: ty.Tuple[str, str, str, str], + log_emails: ty.List[LogEmail], + mail_server: ty.Tuple[MailServer], delete: bool, raise_errors: bool, xnat_login: ty.Optional[ty.Tuple[str, str, str]], clean_up_older_than: int, ): - staging_dir = Path(staging_dir) if not staging_dir.exists(): raise ValueError(f"Staging directory '{staging_dir}' does not exist") diff --git a/xnat_ingest/cli/upload.py b/xnat_ingest/cli/upload.py index e249e33..e4f084a 100644 --- a/xnat_ingest/cli/upload.py +++ b/xnat_ingest/cli/upload.py @@ -60,7 +60,7 @@ @click.option( "--log-file", default=None, - type=LogFile(), + type=LogFile, nargs=2, metavar=" ", envvar="XNAT_INGEST_LOGFILE", @@ -72,7 +72,7 @@ @click.option( "--log-email", "log_emails", - type=LogEmail(), + type=LogEmail, nargs=3, metavar="
", multiple=True, @@ -84,7 +84,7 @@ ) @click.option( "--mail-server", - type=MailServer(), + type=MailServer, metavar=" ", default=None, envvar="XNAT_INGEST_MAILSERVER",