This repository has been archived by the owner on Apr 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
run.py
executable file
·54 lines (39 loc) · 1.62 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
"""Main script for dicom-send gear."""
import logging
import os
import flywheel
import flywheel_gear_toolkit
from utils import parse_config
from utils import dicom_send
from utils import report_generator
def main(gear_context):
"""Orchestrate dicom-send gear."""
log.info("Starting dicom-send gear.")
# Prepare gear arguments by parsing the gear configuration
gear_args, download = parse_config.generate_gear_args(gear_context)
# Run dicom-send
if download is True:
DICOMS_PRESENT, DICOMS_SENT = dicom_send.download_and_send(**gear_args)
session_id = gear_args['session_id']
elif download is False:
session_id = gear_args.pop('session_id')
DICOMS_PRESENT, DICOMS_SENT = dicom_send.run(**gear_args)
report_generator.upload_report(gear_args['api_key'], session_id, gear_args.get('parent_acq'))
# Log number of DICOM files transmitted and exit accordingly
if DICOMS_SENT == 0:
log.error("No DICOM files were transmitted. Exiting.")
os.sys.exit(1)
elif DICOMS_SENT < DICOMS_PRESENT:
log.error("Not all DICOMS were successfully transmitted. Please check report.")
os.sys.exit(1)
else:
log.info(f"!!! TOTAL -- There were {DICOMS_SENT} DICOM files transmitted.")
exit_status = 0
return exit_status
if __name__ == "__main__":
with flywheel_gear_toolkit.GearToolkitContext() as gear_context:
gear_context.init_logging()
log = gear_context.log
exit_status = main(gear_context)
log.info(f"Successful dicom-send gear execution with exit status {exit_status}.")