Skip to content

Commit

Permalink
fiddling with click types
Browse files Browse the repository at this point in the history
  • Loading branch information
tclose committed Mar 14, 2024
1 parent 0121350 commit 1d4690e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
19 changes: 10 additions & 9 deletions xnat_ingest/cli/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,23 @@
)
@click.option(
"--associated-files",
type=AssociatedFiles(),
type=AssociatedFiles,
nargs=2,
default=None,
envvar="XNAT_INGEST_ASSOCIATED",
metavar="<glob> <id-pattern>",
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 "
"<GIVEN-NAME>_<FAMILY-NAME>. 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<id>\d+)\.(?P<type>\w+)\..*'"
Expand All @@ -98,7 +98,7 @@
@click.option(
"--log-file",
default=None,
type=LogFile(),
type=LogFile,
nargs=2,
metavar="<path> <loglevel>",
envvar="XNAT_INGEST_LOGFILE",
Expand All @@ -110,7 +110,7 @@
@click.option(
"--log-email",
"log_emails",
type=LogEmail(),
type=LogEmail,
nargs=3,
metavar="<address> <loglevel> <subject-preamble>",
multiple=True,
Expand All @@ -122,7 +122,7 @@
)
@click.option(
"--mail-server",
type=MailServer(),
type=MailServer,
nargs=4,
metavar="<host> <sender-email> <user> <password>",
default=None,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
)
Expand Down
17 changes: 8 additions & 9 deletions xnat_ingest/cli/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="<access-key> <secret-key>",
envvar="XNAT_INGEST_STORE_CREDENTIALS",
default=None,
Expand All @@ -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="<path> <loglevel>",
envvar="XNAT_INGEST_LOGFILE",
Expand All @@ -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="<address> <loglevel> <subject-preamble>",
multiple=True,
Expand All @@ -123,7 +123,7 @@ def remove_old_files_on_ssh(remote_store: str, threshold: int):
)
@click.option(
"--mail-server",
type=MailServer(),
type=MailServer,
metavar="<host> <sender-email> <user> <password>",
default=None,
envvar="XNAT_INGEST_MAILSERVER",
Expand Down Expand Up @@ -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")

Expand Down
6 changes: 3 additions & 3 deletions xnat_ingest/cli/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
@click.option(
"--log-file",
default=None,
type=LogFile(),
type=LogFile,
nargs=2,
metavar="<path> <loglevel>",
envvar="XNAT_INGEST_LOGFILE",
Expand All @@ -72,7 +72,7 @@
@click.option(
"--log-email",
"log_emails",
type=LogEmail(),
type=LogEmail,
nargs=3,
metavar="<address> <loglevel> <subject-preamble>",
multiple=True,
Expand All @@ -84,7 +84,7 @@
)
@click.option(
"--mail-server",
type=MailServer(),
type=MailServer,
metavar="<host> <sender-email> <user> <password>",
default=None,
envvar="XNAT_INGEST_MAILSERVER",
Expand Down

0 comments on commit 1d4690e

Please sign in to comment.