How to use the dax.errors.SpiderError 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 / spiders.py View on Github external
cmd_args is a dictionary:
            exe: executable to use (matlab, python, sh)
            template: string defining the command line with argument
            args: dictionary with:
                    key = argument
                    value = value to set
            filename: name for the file if written into a file (optional)
        :return: True if succeeded, False otherwise
        """
        self.time_writer('-------- run_cmd_args --------')
        # Check cmd_args set by user:
        cmd_keys = list(self.cmd_args.keys())
        if not self.cmd_args:
            raise SpiderError("self.cmd_args not defined.")
        if 'exe' not in cmd_keys:
            raise SpiderError("self.cmd_args doesn't have a key 'exe'.")
        elif not XnatUtils.executable_exists(self.cmd_args['exe']):
            msg = "Executable not found: %s."
            raise SpiderError(msg % self.cmd_args['exe'])
        if 'template' not in cmd_keys:
            msg = "self.cmd_args doesn't have a key 'template'."
            raise SpiderError(msg)
        if 'args' not in cmd_keys:
            raise SpiderError("self.cmd_args doesn't have a key 'args'.")

        # Add options to matlab if it's not present in the exe
        cmd = ''
        template = Template(self.cmd_args['template'])
        exe = self.cmd_args['exe']
        if exe.lower() == 'matlab':
            exe = 'matlab -singleCompThread -nodesktop -nosplash < '
            # add file to run the matlab command if not set
github VUIIS / dax / dax / spiders.py View on Github external
:param resource: folder name to upload to on the assessor
        :raises: ValueError if the file to upload does not exist
        :return: None

        """
        self.has_spider_handler()
        if os.path.isfile(fpath):
            if resource == 'PDF':
                self.spider_handler.add_pdf(fpath)
            else:
                self.spider_handler.add_file(fpath, resource)
        elif os.path.isdir(fpath):
            self.spider_handler.add_folder(fpath, resource)
        else:
            err = "upload(): file path does not exist: %s" % (fpath)
            raise SpiderError(err)
github VUIIS / dax / dax / spiders.py View on Github external
Run a command line via os.system() with arguments set in self.cmd_args

        cmd_args is a dictionary:
            exe: executable to use (matlab, python, sh)
            template: string defining the command line with argument
            args: dictionary with:
                    key = argument
                    value = value to set
            filename: name for the file if written into a file (optional)
        :return: True if succeeded, False otherwise
        """
        self.time_writer('-------- run_cmd_args --------')
        # Check cmd_args set by user:
        cmd_keys = list(self.cmd_args.keys())
        if not self.cmd_args:
            raise SpiderError("self.cmd_args not defined.")
        if 'exe' not in cmd_keys:
            raise SpiderError("self.cmd_args doesn't have a key 'exe'.")
        elif not XnatUtils.executable_exists(self.cmd_args['exe']):
            msg = "Executable not found: %s."
            raise SpiderError(msg % self.cmd_args['exe'])
        if 'template' not in cmd_keys:
            msg = "self.cmd_args doesn't have a key 'template'."
            raise SpiderError(msg)
        if 'args' not in cmd_keys:
            raise SpiderError("self.cmd_args doesn't have a key 'args'.")

        # Add options to matlab if it's not present in the exe
        cmd = ''
        template = Template(self.cmd_args['template'])
        exe = self.cmd_args['exe']
        if exe.lower() == 'matlab':
github VUIIS / dax / dax / spiders.py View on Github external
:param executable: executable path
        :param name: name of Executable
        :return: Complete path to the executable
        """
        if executable == name:
            if not XnatUtils.executable_exists(executable):
                raise SpiderError("Executable '%s' not found on your computer."
                                  % name)
        else:
            executable = os.path.abspath(executable)
            if not executable.endswith(name):
                if os.path.isdir(executable):
                    executable = os.path.join(executable, name)
                else:
                    msg = "Error for executable path '%s': Wrong name."
                    raise SpiderError(msg % executable)
            if not os.path.isfile(executable):
                msg = "Executable '%s' not found"
                raise SpiderError(msg % executable)

        self.get_exe_version(executable, version_opt)
        return executable
github VUIIS / dax / dax / spiders.py View on Github external
'type': 'scan' or 'assessor' or 'subject' or 'project' or 'session'
            'label': label on XNAT (not needed for session/subject/project)
            'resource': name of resource to download or list of resources
            'dir': directory to download files into (optional)
          - for assessor only if not giving the label but just proctype
            'scan': id of the scan for the assessor (if None, sessionAssessor)

        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()
github VUIIS / dax / dax / spiders.py View on Github external
'dir': directory to download files into (optional)
          - for assessor only if not giving the label but just proctype
            'scan': id of the scan for the assessor (if None, sessionAssessor)

        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,
github VUIIS / dax / dax / spiders.py View on Github external
"""
        self.time_writer('-------- run_cmd_args --------')
        # Check cmd_args set by user:
        cmd_keys = list(self.cmd_args.keys())
        if not self.cmd_args:
            raise SpiderError("self.cmd_args not defined.")
        if 'exe' not in cmd_keys:
            raise SpiderError("self.cmd_args doesn't have a key 'exe'.")
        elif not XnatUtils.executable_exists(self.cmd_args['exe']):
            msg = "Executable not found: %s."
            raise SpiderError(msg % self.cmd_args['exe'])
        if 'template' not in cmd_keys:
            msg = "self.cmd_args doesn't have a key 'template'."
            raise SpiderError(msg)
        if 'args' not in cmd_keys:
            raise SpiderError("self.cmd_args doesn't have a key 'args'.")

        # Add options to matlab if it's not present in the exe
        cmd = ''
        template = Template(self.cmd_args['template'])
        exe = self.cmd_args['exe']
        if exe.lower() == 'matlab':
            exe = 'matlab -singleCompThread -nodesktop -nosplash < '
            # add file to run the matlab command if not set
            if 'filename' not in cmd_keys:
                self.cmd_args['filename'] = os.path.join(
                    self.jobdir, 'run_%s_matlab.m' % self.xnat_session)

        # Write the template in file and call the executable on the file
        if 'filename' in cmd_keys:
            if not os.path.exists(os.path.dirname(self.cmd_args['filename'])):
                raise SpiderError("Folder for %s does not exist."
github VUIIS / dax / dax / spiders.py View on Github external
args: dictionary with:
                    key = argument
                    value = value to set
            filename: name for the file if written into a file (optional)
        :return: True if succeeded, False otherwise
        """
        self.time_writer('-------- run_cmd_args --------')
        # Check cmd_args set by user:
        cmd_keys = list(self.cmd_args.keys())
        if not self.cmd_args:
            raise SpiderError("self.cmd_args not defined.")
        if 'exe' not in cmd_keys:
            raise SpiderError("self.cmd_args doesn't have a key 'exe'.")
        elif not XnatUtils.executable_exists(self.cmd_args['exe']):
            msg = "Executable not found: %s."
            raise SpiderError(msg % self.cmd_args['exe'])
        if 'template' not in cmd_keys:
            msg = "self.cmd_args doesn't have a key 'template'."
            raise SpiderError(msg)
        if 'args' not in cmd_keys:
            raise SpiderError("self.cmd_args doesn't have a key 'args'.")

        # Add options to matlab if it's not present in the exe
        cmd = ''
        template = Template(self.cmd_args['template'])
        exe = self.cmd_args['exe']
        if exe.lower() == 'matlab':
            exe = 'matlab -singleCompThread -nodesktop -nosplash < '
            # add file to run the matlab command if not set
            if 'filename' not in cmd_keys:
                self.cmd_args['filename'] = os.path.join(
                    self.jobdir, 'run_%s_matlab.m' % self.xnat_session)
github VUIIS / dax / dax / spiders.py View on Github external
filename: name for the file if written into a file (optional)
        :return: True if succeeded, False otherwise
        """
        self.time_writer('-------- run_cmd_args --------')
        # Check cmd_args set by user:
        cmd_keys = list(self.cmd_args.keys())
        if not self.cmd_args:
            raise SpiderError("self.cmd_args not defined.")
        if 'exe' not in cmd_keys:
            raise SpiderError("self.cmd_args doesn't have a key 'exe'.")
        elif not XnatUtils.executable_exists(self.cmd_args['exe']):
            msg = "Executable not found: %s."
            raise SpiderError(msg % self.cmd_args['exe'])
        if 'template' not in cmd_keys:
            msg = "self.cmd_args doesn't have a key 'template'."
            raise SpiderError(msg)
        if 'args' not in cmd_keys:
            raise SpiderError("self.cmd_args doesn't have a key 'args'.")

        # Add options to matlab if it's not present in the exe
        cmd = ''
        template = Template(self.cmd_args['template'])
        exe = self.cmd_args['exe']
        if exe.lower() == 'matlab':
            exe = 'matlab -singleCompThread -nodesktop -nosplash < '
            # add file to run the matlab command if not set
            if 'filename' not in cmd_keys:
                self.cmd_args['filename'] = os.path.join(
                    self.jobdir, 'run_%s_matlab.m' % self.xnat_session)

        # Write the template in file and call the executable on the file
        if 'filename' in cmd_keys: