Skip to content

Commit

Permalink
Merge pull request #366 from DESm1th/fixes
Browse files Browse the repository at this point in the history
[FIX] Add small bug fixes + log message improvements
  • Loading branch information
DESm1th authored Nov 11, 2024
2 parents dc73a79 + 31bc142 commit 40a6a58
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
3 changes: 2 additions & 1 deletion bin/dm_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ def link_archive(archive_path, dicom_path, scanid_field, config):
scanid = get_scanid_from_header(archive_path, scanid_field)

if not scanid:
logger.error("Scanid not found for archive: {}".format(archive_path))
logger.error("Scanid not found for archive, please add intended ID "
f"to 'scans.csv': {archive_path}")
return

try:
Expand Down
2 changes: 1 addition & 1 deletion bin/dm_link_shared_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def share_session(record, xnat_connection=None):

target_cfg = datman.config.config(study=str(target))
try:
target_tags = list(target_cfg.get_tags(site=source.site))
target_tags = list(target_cfg.get_tags(site=target.site))
except Exception:
target_tags = []

Expand Down
6 changes: 4 additions & 2 deletions bin/dm_redcap_scan_completed.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,14 @@ def add_session_redcap(record, record_key):
try:
datman.scanid.is_scanid(subject_id)
except datman.scanid.ParseException:
logger.error('Invalid session: {}, skipping'.format(subject_id))
logger.error(f'Invalid session {subject_id} in record {record_id}, '
'skipping. Please fix ID on REDCap.')
return
try:
ident = parse_id(subject_id)
except datman.scanid.ParseException:
logger.error('Invalid session: {}, skipping'.format(subject_id))
logger.error(f'Invalid session {subject_id} in record {record_id}, '
'skipping. Please fix ID on REDCap.')
return

session_date = record[get_setting('RedcapDate', default='date')]
Expand Down
4 changes: 2 additions & 2 deletions bin/dm_xnat_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,8 @@ def get_experiment_identifier(config, project, experiment_id):
try:
ident = validate_subject_id(experiment_id, config)
except datman.scanid.ParseException:
logger.error(f"Invalid experiment ID {experiment_id} in project "
f"{project}.")
logger.error(f"Invalid XNAT experiment ID {experiment_id} in project "
f"{project}. Please update XNAT with correct ID.")
return

if ident.session is None and not datman.scanid.is_phantom(ident):
Expand Down
14 changes: 12 additions & 2 deletions datman/xnat.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ def __init__(self, server, username, password):
self.auth = (username, password)
try:
self.open_session()
except Exception:
raise XnatException(f"Failed to open session with server {server}")
except Exception as e:
raise XnatException(
f"Failed to open session with server {server}. Reason - {e}")

def __enter__(self):
return self
Expand All @@ -206,6 +207,15 @@ def open_session(self):
logger.debug("Username: {}")
response.raise_for_status()

# If password is expired, XNAT returns status 200 and a sea of
# HTML causing later, unexpected, exceptions when using
# the connection. So! Check to see if we got HTML instead of a token.
if '<html' in response.text:
raise XnatException(
f"Password for user {self.auth[0]} on server {self.server} "
"has expired. Please update it."
)

# Cookies are set automatically, don't manually set them or it wipes
# out other session info
self.session = s
Expand Down

0 comments on commit 40a6a58

Please sign in to comment.