Skip to content

Commit

Permalink
renamed prefix for CLI env vars to XINGEST and ensured all options ha…
Browse files Browse the repository at this point in the history
…ve an envvar
  • Loading branch information
tclose committed Sep 28, 2024
1 parent b28669e commit ffb2648
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 65 deletions.
18 changes: 9 additions & 9 deletions real-tests/usyd_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
stage,
[],
env={
"XNAT_INGEST_STAGE_DICOMS_PATH": "/vol/vmhost/kubernetes/<path>/<to>/<dicom>/<store>/**/*.IMA",
"XNAT_INGEST_STAGE_DIR": "/vol/vmhost/usyd-data-export/STAGING",
"XNAT_INGEST_STAGE_PROJECT": "ProtocolName",
"XNAT_INGEST_STAGE_SUBJECT": "PatientID",
"XNAT_INGEST_STAGE_VISIT": "AccessionNumber",
"XNAT_INGEST_STAGE_ASSOCIATED": '"/vol/vmhost/usyd-data-export/RAW-DATA-EXPORT/{PatientName.family_name}_{PatientName.given_name}/.ptd","./[^\\.]+.[^\\.]+.[^\\.]+.(?P\\d+).[A-Z]+_(?P[^\\.]+)."',
"XNAT_INGEST_STAGE_DELETE": "0",
"XNAT_INGEST_STAGE_LOGFILE": "<somewhere-sensible>,INFO",
"XNAT_INGEST_STAGE_DEIDENTIFY": "1",
"XINGEST_DICOMS_PATH": "/vol/vmhost/kubernetes/<path>/<to>/<dicom>/<store>/**/*.IMA",
"XINGEST_DIR": "/vol/vmhost/usyd-data-export/STAGING",
"XINGEST_PROJECT": "ProtocolName",
"XINGEST_SUBJECT": "PatientID",
"XINGEST_VISIT": "AccessionNumber",
"XINGEST_ASSOCIATED": '"/vol/vmhost/usyd-data-export/RAW-DATA-EXPORT/{PatientName.family_name}_{PatientName.given_name}/.ptd","./[^\\.]+.[^\\.]+.[^\\.]+.(?P\\d+).[A-Z]+_(?P[^\\.]+)."',
"XINGEST_DELETE": "0",
"XINGEST_LOGFILE": "<somewhere-sensible>,INFO",
"XINGEST_DEIDENTIFY": "1",
},
catch_exceptions=False,
)
Expand Down
2 changes: 1 addition & 1 deletion real-tests/usyd_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
transfer,
[],
env={
"XNAT_INGEST_STAGE_DIR": "/Users/tclose/Data/testing/staging-test/",
"XINGEST_DIR": "/Users/tclose/Data/testing/staging-test/",
"XNAT_INGEST_TRANSFER_LOGFILE": "/Users/tclose/Desktop/test-log.log,INFO",
"XNAT_INGEST_TRANSFER_DELETE": "0",
},
Expand Down
22 changes: 11 additions & 11 deletions real-tests/usyd_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
upload,
[],
env={
"XNAT_INGEST_UPLOAD_STAGED": "<s3-bucket>",
"XNAT_INGEST_UPLOAD_HOST": "https://xnat.sydney.edu.au",
"XNAT_INGEST_UPLOAD_USER": "<role-account-user>",
"XNAT_INGEST_UPLOAD_PASS": "<role-account-pass>",
"XNAT_INGEST_UPLOAD_ALWAYSINCLUDE": "medimage/dicom-series",
"XNAT_INGEST_UPLOAD_STORE_CREDENTIALS": "<s3-bucket-access-key>,<s3-bucket-access-secret>",
"XNAT_INGEST_UPLOAD_LOGFILE": "<somewhere-sensible>,INFO",
"XNAT_INGEST_UPLOAD_DELETE": "0",
"XNAT_INGEST_UPLOAD_TEMPDIR": "<somewhere-else-sensible>",
"XNAT_INGEST_UPLOAD_REQUIRE_MANIFEST": "1",
"XNAT_INGEST_UPLOAD_CLEANUP_OLDER_THAN": "30",
"XINGEST_STAGED": "<s3-bucket>",
"XINGEST_HOST": "https://xnat.sydney.edu.au",
"XINGEST_USER": "<role-account-user>",
"XINGEST_PASS": "<role-account-pass>",
"XINGEST_ALWAYSINCLUDE": "medimage/dicom-series",
"XINGEST_STORE_CREDENTIALS": "<s3-bucket-access-key>,<s3-bucket-access-secret>",
"XINGEST_LOGFILE": "<somewhere-sensible>,INFO",
"XINGEST_DELETE": "0",
"XINGEST_TEMPDIR": "<somewhere-else-sensible>",
"XINGEST_REQUIRE_MANIFEST": "1",
"XINGEST_CLEANUP_OLDER_THAN": "30",
},
catch_exceptions=False,
)
Expand Down
48 changes: 26 additions & 22 deletions xnat_ingest/cli/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,38 +37,36 @@
are uploaded to XNAT
""",
)
@click.argument("files_path", type=str, envvar="XNAT_INGEST_STAGE_DICOMS_PATH")
@click.argument(
"output_dir", type=click.Path(path_type=Path), envvar="XNAT_INGEST_STAGE_DIR"
)
@click.argument("files_path", type=str, envvar="XINGEST_DICOMS_PATH")
@click.argument("output_dir", type=click.Path(path_type=Path), envvar="XINGEST_DIR")
@click.option(
"--datatype",
type=str,
metavar="<mime-type>",
multiple=True,
default=["medimage/dicom-series"],
envvar="XNAT_INGEST_STAGE_DATATYPE",
envvar="XINGEST_DATATYPE",
help="The datatype of the primary files to to upload",
)
@click.option(
"--project-field",
type=str,
default="StudyID",
envvar="XNAT_INGEST_STAGE_PROJECT",
envvar="XINGEST_PROJECT",
help=("The keyword of the metadata field to extract the XNAT project ID from "),
)
@click.option(
"--subject-field",
type=str,
default="PatientID",
envvar="XNAT_INGEST_STAGE_SUBJECT",
envvar="XINGEST_SUBJECT",
help=("The keyword of the metadata field to extract the XNAT subject ID from "),
)
@click.option(
"--visit-field",
type=str,
default="AccessionNumber",
envvar="XNAT_INGEST_STAGE_VISIT",
envvar="XINGEST_VISIT",
help=(
"The keyword of the metadata field to extract the XNAT imaging session ID from "
),
Expand All @@ -77,7 +75,7 @@
"--session-field",
type=str,
default=None,
envvar="XNAT_INGEST_STAGE_SESSION",
envvar="XINGEST_SESSION",
help=(
"The keyword of the metadata field to extract the XNAT imaging session ID from "
),
Expand All @@ -86,7 +84,7 @@
"--scan-id-field",
type=str,
default="SeriesNumber",
envvar="XNAT_INGEST_STAGE_SCAN_ID",
envvar="XINGEST_SCAN_ID",
help=(
"The keyword of the metadata field to extract the XNAT imaging scan ID from "
),
Expand All @@ -95,7 +93,7 @@
"--scan-desc-field",
type=str,
default="SeriesDescription",
envvar="XNAT_INGEST_STAGE_SCAN_DESC",
envvar="XINGEST_SCAN_DESC",
help=(
"The keyword of the metadata field to extract the XNAT imaging scan description from "
),
Expand All @@ -104,7 +102,7 @@
"--resource-field",
type=str,
default="ImageType[-1]",
envvar="XNAT_INGEST_STAGE_RESOURCE",
envvar="XINGEST_RESOURCE",
help=(
"The keyword of the metadata field to extract the XNAT imaging resource ID from "
),
Expand All @@ -121,7 +119,7 @@
nargs=3,
default=None,
multiple=True,
envvar="XNAT_INGEST_STAGE_ASSOCIATED",
envvar="XINGEST_ASSOCIATED",
metavar="<datatype> <glob> <id-pattern>",
help=(
'The "glob" arg is a glob pattern by which to detect associated files to be '
Expand All @@ -143,14 +141,14 @@
@click.option(
"--delete/--dont-delete",
default=False,
envvar="XNAT_INGEST_STAGE_DELETE",
envvar="XINGEST_DELETE",
help="Whether to delete the session directories after they have been uploaded or not",
)
@click.option(
"--log-level",
default="info",
type=str,
envvar="XNAT_INGEST_STAGE_LOGLEVEL",
envvar="XINGEST_LOGLEVEL",
help=("The level of the logging printed to stdout"),
)
@click.option(
Expand All @@ -161,7 +159,7 @@
multiple=True,
nargs=2,
metavar="<path> <loglevel>",
envvar="XNAT_INGEST_STAGE_LOGFILE",
envvar="XINGEST_LOGFILE",
help=(
'Location to write the output logs to, defaults to "upload-logs" in the '
"export directory"
Expand All @@ -174,7 +172,7 @@
nargs=3,
metavar="<address> <loglevel> <subject-preamble>",
multiple=True,
envvar="XNAT_INGEST_STAGE_LOGEMAIL",
envvar="XINGEST_LOGEMAIL",
help=(
"Email(s) to send logs to. When provided in an environment variable, "
"mail and log level are delimited by ',' and separate destinations by ';'"
Expand All @@ -185,7 +183,7 @@
type=str,
multiple=True,
default=(),
envvar="XNAT_INGEST_UPLOAD_LOGGERS",
envvar="XINGEST_LOGGERS",
help=(
"The loggers to use for logging. By default just the 'xnat-ingest' logger is used. "
"But additional loggers can be included (e.g. 'xnat') can be "
Expand All @@ -198,7 +196,7 @@
nargs=4,
metavar="<host> <sender-email> <user> <password>",
default=None,
envvar="XNAT_INGEST_STAGE_MAILSERVER",
envvar="XINGEST_MAILSERVER",
help=(
"the mail server to send logger emails to. When provided in an environment variable, "
"args are delimited by ';'"
Expand All @@ -214,7 +212,7 @@
"--deidentify/--dont-deidentify",
default=False,
type=bool,
envvar="XNAT_INGEST_STAGE_DEIDENTIFY",
envvar="XINGEST_DEIDENTIFY",
help="whether to deidentify the file names and DICOM metadata before staging",
)
@click.option(
Expand All @@ -230,14 +228,14 @@
"--spaces-to-underscores/--no-spaces-to-underscores",
default=False,
help="Whether to replace spaces with underscores in the filenames of associated files",
envvar="XNAT_INGEST_STAGE_SPACES_TO_UNDERSCORES",
envvar="XINGEST_SPACES_TO_UNDERSCORES",
type=bool,
)
@click.option(
"--work-dir",
type=click.Path(path_type=Path),
default=None,
envvar="XNAT_INGEST_STAGE_WORK_DIR",
envvar="XINGEST_WORK_DIR",
help=(
"The working directory to use for temporary files. Should be on the same "
"physical disk as the staging directory for optimal performance"
Expand All @@ -247,36 +245,42 @@
"--copy-mode",
type=FileSet.CopyMode,
default=FileSet.CopyMode.hardlink_or_copy,
envvar="XINGEST_COPY_MODE",
help="The method to use for copying files",
)
@click.option(
"--loop",
type=int,
default=None,
envvar="XINGEST_LOOP",
help="Run the staging process continuously every LOOP seconds",
)
@click.option(
"--pre-stage-dir-name",
type=str,
default=PRE_STAGE_NAME_DEFAULT,
envvar="XINGEST_PRE_STAGE_DIR_NAME",
help="The name of the directory to use for pre-staging the files",
)
@click.option(
"--staged-dir-name",
type=str,
default=STAGED_NAME_DEFAULT,
envvar="XINGEST_STAGED_DIR_NAME",
help="The name of the directory to use for staging the files",
)
@click.option(
"--invalid-dir-name",
type=str,
default=INVALID_NAME_DEFAULT,
envvar="XINGEST_INVALID_DIR_NAME",
help="The name of the directory to use for invalid files",
)
@click.option(
"--deidentified-dir-name",
type=str,
default=DEIDENTIFIED_NAME_DEFAULT,
envvar="XINGEST_DEIDENTIFIED_DIR_NAME",
help="The name of the directory to use for deidentified files",
)
def stage(
Expand Down
Loading

0 comments on commit ffb2648

Please sign in to comment.