Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions lochness/xnat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,17 @@ def clear_stored_credentials(dataorc_bindary_path: Path):
child.expect(pexpect.EOF, timeout=None)


def get_xnat_session(Lochness, subject):
alias = subject.xnat.keys()[0]
keyring = Lochness['keyring'][alias]
xnat_session = xnat.connect(keyring['URL'],
keyring['USERNAME'],
keyring['PASSWORD'])
return xnat_session


@net.retry(max_attempts=5)
def sync_xnatpy(Lochness, subject, dry=False):
def sync_xnatpy(Lochness, subject, dry=False, session=None):
"""A new sync function with XNATpy"""
logger.debug('exploring {0}/{1}'.format(subject.study, subject.id))

Expand All @@ -236,10 +245,8 @@ def sync_xnatpy(Lochness, subject, dry=False):
logger.warning(f'Failed to remove {tmp_file}: {e}')

for alias, xnat_uids in iter(subject.xnat.items()):
keyring = Lochness['keyring'][alias]
session = xnat.connect(keyring['URL'],
keyring['USERNAME'],
keyring['PASSWORD'])
if session is None:
session = get_xnat_session(Lochness, subject)
'''
pull XNAT data agnostic to the case of subject IDs loop over lower and
upper case IDs if the data for one ID do not exist, experiments(auth,
Expand Down
7 changes: 6 additions & 1 deletion scripts/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from datetime import datetime, date
from lochness.cleaner import rm_transferred_files_under_phoenix
from lochness.utils.source_check import check_source
from lochness.xnat import get_xnat_session
# import dpanonymize

SOURCES = {
Expand Down Expand Up @@ -229,6 +230,7 @@ def do(args, Lochness):
multiple_site, upenn_redcap)

n = 0
xnat_session = None
for subject in lochness.read_phoenix_metadata(Lochness, args.studies):
if n == 0:
save_redcap_metadata(Lochness, subject)
Expand All @@ -249,8 +251,11 @@ def do(args, Lochness):
else:
for source, Module in zip(args.input_sources, args.source):
if source == 'xnat':
if xnat_session is None:
xnat_session = get_xnat_session(Lochness, subject)
lochness.attempt(Module.sync_xnatpy, Lochness,
subject, dry=args.dry)
subject, dry=args.dry,
session=xnat_session)
else:
lochness.attempt(Module.sync, Lochness,
subject, dry=args.dry)
Expand Down