How to use the dax.XnatUtils.get_interface function in dax

To help you get started, we’ve selected a few dax examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github VUIIS / dax / dax / dax_tools_utils.py View on Github external
"""
    Main function to upload the results / PBS / OUTLOG of assessors
     from the queue folder

    :param upload_settings: dictionary defining the upload information
    :return: None
    """
    if len(os.listdir(RESULTS_DIR)) == 0:
        LOGGER.warn('No data need to be uploaded.\n')
        sys.exit()

    warnings = list()

    for upload_dict in upload_settings:
        try:
            with XnatUtils.get_interface(host=upload_dict['host'],
                                         user=upload_dict['username'],
                                         pwd=upload_dict['password']) as intf:
                LOGGER.info('='*50)
                proj_str = (upload_dict['projects'] if upload_dict['projects']
                            else 'all')
                LOGGER.info('Connecting to XNAT <%s>, upload for projects:%s' %
                            (upload_dict['host'], proj_str))
                if not XnatUtils.has_dax_datatypes(intf):
                    msg = 'dax datatypes are not installed on xnat <%s>.'
                    raise DaxUploadError(msg % (upload_dict['host']))

                # 1) Upload the assessor data
                # For each assessor label that need to be upload :
                LOGGER.info('Uploading results for assessors')
                if DAX_SETTINGS.get_use_reference():
                    LOGGER.info('using upload by reference, dir is:{}'.format(
github VUIIS / dax / bin / supplemental_tools / Xnatreport_assessor.py View on Github external
import pandas
import pyxnat
from dax import XnatUtils
from dax import utilities

if len(sys.argv)!=4 :
    print('Usage:')
    print('python Xnatreport_assessor.py   ')
    sys.exit()


project = sys.argv[1]
proctype = sys.argv[2]
outfile = sys.argv[3]

xnat = XnatUtils.get_interface()

Assrs = xnat.list_project_assessors(project)

R = list()
for assr in Assrs :

    if assr.get('proctype') != proctype : continue

    #print(assr['assessor_label'])

    # Get desired fields
    thisR = {}
    for key in ('project_label','subject_label','session_label','proctype',
                'assessor_id','procstatus','qcstatus','assessor_label') :
        thisR[key] = assr[key]
github VUIIS / dax / dax / dax_tools_utils.py View on Github external
host=_host, user=_user)))
        # set test object:
        tests.set_tobj(test_obj)

        # Make the temp dir:
        if not os.path.isdir(DAX_TEST_DIR):
            os.makedirs(DAX_TEST_DIR)

        # Set the log of any dax function to a temp file for user:
        if hide:
            logfile = os.path.join(DAX_TEST_DIR, 'dax_test.log')
        else:
            logfile = None
        log.setup_debug_logger('dax', logfile)

        with XnatUtils.get_interface(host=_host, user=username) as intf:
            tests.set_xnat(intf)
            tests.run_test(project, sessions, nb_sess)

    print((TD_END.format(nb_test=tests.get_number(),
                        time="%.3f" % tests.get_time(),
                        state=tests.get_test_state())))

    if do_not_remove:
        if 'OK' == tests.get_test_state()[:2]:
            shutil.rmtree(DAX_TEST_DIR)
github VUIIS / dax / dax / spiders.py View on Github external
def download_xnat_file(self, src, dst):
        """Download XNAT specific file."""
        results = None
        with XnatUtils.get_interface(host=self.host, user=self.user,
                                     pwd=self.pwd) as xnat:
            try:
                _res, _file = src.split('/files/')
                res = xnat.select(_res)
                if not res.exists():
                    msg = 'resources specified by %s not found on XNAT.'
                    raise AutoSpiderError(msg % src)
            except Exception:
                msg = 'resources can not be checked because the path given is \
wrong for XNAT. Please check https://wiki.xnat.org/display/XNAT16/\
XNAT+REST+API+Directory for the path.'
                raise AutoSpiderError(msg % src)
            try:
                results = res.file(_file).get(dst)
            except Exception:
                raise AutoSpiderError('downloading files from XNAT failed.')
github VUIIS / dax / dax / spiders.py View on Github external
def download_xnat_resource(self, src, dst):
        """Download XNAT complete resource."""
        results = None
        with XnatUtils.get_interface(host=self.host, user=self.user,
                                     pwd=self.pwd) as xnat:
            try:
                res = xnat.select(src)
                if not res.exists():
                    msg = 'resources specified by %s not found on XNAT.'
                    raise AutoSpiderError(msg % src)
            except Exception:
                msg = 'resources can not be checked because the path given is \
wrong for XNAT: %s. Please check https://wiki.xnat.org/display/XNAT16/\
XNAT+REST+API+Directory for the path.'
                raise AutoSpiderError(msg % src)

            try:
                # res.get(dst, extract=True)
                results = XnatUtils.download_files_from_obj(dst, res)
                if len(results) == 1:
github VUIIS / dax / bin / supplemental_tools / Xnatreport_assessors.py View on Github external
import sys
import pandas
import pyxnat
import argparse
import time
from dax import XnatUtils
from dax import utilities

# Specify and parse command line arguments
parser = argparse.ArgumentParser()
parser.add_argument('project',help='Project name')
args = parser.parse_args()
print('Project: {}'.format(args.project))


xnat = XnatUtils.get_interface()
Assrs = xnat.list_project_assessors(args.project)
xnat.disconnect()

timestamp = time.strftime("%Y%m%d%H%M%S")
outfile1 = 'status_by_assessor_{}_{}.csv'.format(args.project,timestamp)
outfile2 = 'status_by_session_{}_{}.csv'.format(args.project,timestamp)

R = list()
for assr in Assrs :

    #print(assr['assessor_label'])

    # Get desired fields
    thisR = {}
    for key in ('project_label','subject_label','session_label','proctype',
            'assessor_id','procstatus','qcstatus','qcnotes','assessor_label') :
github VUIIS / dax / dax / spiders.py View on Github external
self.data = list of dictionary with keys define below:
            'label': label on XNAT
            'files': list of files downloaded

        set self.data, a python list of the data downloaded.
        """
        self.time_writer('-------- download_inputs --------')
        if not self.inputs:
            raise SpiderError('download_inputs(): self.inputs not define in \
your spider.')
        if not isinstance(self.inputs, list):
            raise SpiderError('self.inputs is not a list: %s' % self.inputs)
        # Inputs folder: jobdir/inputs
        input_dir = os.path.join(self.jobdir, 'inputs')
        with XnatUtils.get_interface(host=self.host, user=self.user,
                                     pwd=self.pwd) as xnat:
            for data_dict in self.inputs:
                if not isinstance(data_dict, dict):
                    raise SpiderError('data in self.inputs is not a dict: %s'
                                      % data_dict)
                if isinstance(data_dict['resource'], list):
                    resources = data_dict['resource']
                else:
                    resources = [data_dict['resource']]
                list_inputs = dict()
                for res in resources:
                    if 'dir' in list(data_dict.keys()):
                        data_folder = os.path.join(input_dir,
                                                   data_dict['dir'])
                    else:
                        data_folder = os.path.join(input_dir,
github VUIIS / dax / dax / bin.py View on Github external
def pi_from_project(project):
    """
    Get the last name of PI who owns the project on XNAT

    :param project: String of the ID of project on XNAT.
    :return: String of the PIs last name

    """
    pi_name = ''
    with XnatUtils.get_interface() as intf:
        proj = intf.select.project(project)
        pi_name = proj.attrs.get('xnat:projectdata/pi/lastname')

    return pi_name
github VUIIS / dax / dax / launcher.py View on Github external
if self.launcher_type == 'diskq-cluster':
            err = 'cannot build jobs with this launcher type: %s'
            raise DaxLauncherError(err % self.launcher_type)

        LOGGER.info('-------------- Build --------------')
        LOGGER.info('launcher_type = %s' % self.launcher_type)
        LOGGER.info('mod delta = %s' % str(mod_delta))

        res_dir = DAX_SETTINGS.get_results_dir()
        flagfile = os.path.join(os.path.join(res_dir, 'FlagFiles'),
                                '%s_%s' % (lockfile_prefix, BUILD_SUFFIX))
        project_list = self.init_script(flagfile, project_local,
                                        type_update=1, start_end=1)

        LOGGER.info('Connecting to XNAT at %s' % self.xnat_host)
        with XnatUtils.get_interface(self.xnat_host, self.xnat_user,
                                     self.xnat_pass) as intf:

            if not XnatUtils.has_dax_datatypes(intf):
                err = 'error: dax datatypes are not installed on xnat <%s>'
                raise DaxXnatError(err % (self.xnat_host))

            # Priority if set:
            if self.priority_project and not project_local:
                unique_list = set(list(self.project_process_dict.keys()) +
                                  list(self.project_modules_dict.keys()))
                project_list = self.get_project_list(list(unique_list))

            # Build projects
            for project_id in project_list:
                LOGGER.info('===== PROJECT: %s =====' % project_id)
                try: