How to use the dax.utilities.read_yaml 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
elif f_settings.endswith('.py'):
            settings = imp.load_source('settings', up_file)
            host_projs = settings.host_projects
        elif f_settings.endswith('.csv'):
            with open(up_file, 'rb') as csvfileread:
                csvreader = csv.reader(csvfileread, delimiter=',')
                for index, row in (csvreader):
                    if len(row) < 4:
                        raise DaxError("error: could not read the csv row. \
Missing args. 4 needed, %s found at line %s." % (str(len(row)), str(index)))
                    else:
                        if row != DEFAULT_HEADER:
                            host_projs.append(dict(list(zip(DEFAULT_HEADER,
                                                        row[:4]))))
        elif f_settings.endswith('.yaml'):
            doc = utilities.read_yaml(f_settings)
            host_projs = doc.get('settings')
        else:
            raise DaxError("error: doesn't recognize the file format for the \
settings file. Please use either JSON/PYTHON/CSV format.")
    else:  # if not file, use the environment variables and options
        _host = os.environ['XNAT_HOST']
        if host:
            _host = host
        if projects:
            projects = projects.split(',')
        else:
            projects = []
        if username:
            username = username
            if not password:
                MSG = "Please provide the password for user <%s> on xnat(%s):"
github VUIIS / dax / dax / dax_tools_utils.py View on Github external
def load_test(filepath):
    """
    Check if a file exists and if it's a python file

    :param filepath: path to the file to test
    :return: True the file pass the test, False otherwise
    """
    if not os.path.exists(filepath):
        print(('[ERROR] %s does not exists.' % filepath))
        return None

    if filepath.endswith('yaml'):
        doc = utilities.read_yaml(filepath)

        if 'projects' in list(doc.keys()):
            try:
                return bin.read_yaml_settings(filepath, LOGGER)
            except AutoProcessorError:
                print('[ERROR]')
                exc_type, exc_value, exc_traceback = sys.exc_info()
                traceback.print_exception(exc_type, exc_value, exc_traceback,
                                          limit=2, file=sys.stdout)
        else:
            # So far only auto processor:
            try:
                return processors.load_from_yaml(XnatUtils, filepath)
            except AutoProcessorError:
                print('[ERROR]')
                exc_type, exc_value, exc_traceback = sys.exc_info()
github VUIIS / dax / dax / bin.py View on Github external
def read_yaml_settings(yaml_file, logger):
    """
    Method to read the settings yaml file and generate the launcher object.

    :param yaml_file: path to yaml file defining the settings
    :return: launcher object
    """
    if not os.path.isfile(yaml_file):
        err = 'Path not found for {}'
        raise DaxError(err.format(yaml_file))

    doc = utilities.read_yaml(yaml_file)

    # Set Inputs from Yaml
    check_default_keys(yaml_file, doc)

    # Set attributes for settings
    attrs = doc.get('attrs')

    # Set singularity image dir
    singularity_imagedir = doc.get('singularity_imagedir')

    # Read modules
    modulelib = doc.get('modulelib')
    mods = dict()
    modules = doc.get('modules', list())
    for mod_dict in modules:
        if mod_dict.get('filepath') is None: