Ejemplo n.º 1
0
def _validate_yaml_defaults(defaults, yaml_file):
    """Validate defaults in clowder loaded from yaml file"""

    _validate_type_dict(defaults, 'defaults', yaml_file)
    if not defaults:
        error = fmt.invalid_entries_error('defaults', defaults, yaml_file)
        raise ClowderError(error)

    if 'ref' not in defaults:
        error = fmt.missing_entry_error('ref', 'defaults', yaml_file)
        raise ClowderError(error)
    _validate_type_str(defaults['ref'], 'ref', yaml_file)
    if not _valid_ref_type(defaults['ref']):
        error = fmt.invalid_ref_error(defaults['ref'], yaml_file)
        raise ClowderError(error)
    del defaults['ref']

    if 'remote' not in defaults:
        error = fmt.missing_entry_error('remote', 'defaults', yaml_file)
        raise ClowderError(error)
    _validate_type_str(defaults['remote'], 'remote', yaml_file)
    del defaults['remote']

    if 'source' not in defaults:
        error = fmt.missing_entry_error('source', 'defaults', yaml_file)
        raise ClowderError(error)
    _validate_type_str(defaults['source'], 'source', yaml_file)
    del defaults['source']

    _validate_yaml_defaults_optional(defaults, yaml_file)

    if defaults:
        error = fmt.invalid_entries_error('defaults', defaults, yaml_file)
        raise ClowderError(error)
Ejemplo n.º 2
0
def _validate_yaml_sources(sources, yaml_file):
    """Validate sources in clowder loaded from yaml file"""

    _validate_type_list(sources, 'sources', yaml_file)
    if not sources:
        error = fmt.invalid_entries_error('sources', sources, yaml_file)
        raise ClowderError(error)

    for source in sources:
        _validate_type_dict(source, 'source', yaml_file)
        if not source:
            error = fmt.invalid_entries_error('source', source, yaml_file)
            raise ClowderError(error)

        if 'name' not in source:
            error = fmt.missing_entry_error('name', 'source', yaml_file)
            raise ClowderError(error)
        _validate_type_str(source['name'], 'name', yaml_file)
        del source['name']

        if 'url' not in source:
            error = fmt.missing_entry_error('url', 'source', yaml_file)
            raise ClowderError(error)
        _validate_type_str(source['url'], 'url', yaml_file)
        del source['url']

        if source:
            error = fmt.invalid_entries_error('source', source, yaml_file)
            raise ClowderError(error)
Ejemplo n.º 3
0
def _validate_yaml_project(project, yaml_file):
    """Validate project in clowder loaded from yaml file"""

    _validate_type_dict(project, 'project', yaml_file)

    if not project:
        error = fmt.invalid_entries_error('project', project, yaml_file)
        raise ClowderError(error)

    if 'name' not in project:
        error = fmt.missing_entry_error('name', 'project', yaml_file)
        raise ClowderError(error)
    _validate_type_str(project['name'], 'name', yaml_file)
    del project['name']

    if 'path' not in project:
        error = fmt.missing_entry_error('path', 'project', yaml_file)
        raise ClowderError(error)
    _validate_type_str(project['path'], 'path', yaml_file)
    del project['path']

    _validate_yaml_project_optional(project, yaml_file)

    if project:
        error = fmt.invalid_entries_error('project', project, yaml_file)
        raise ClowderError(error)
Ejemplo n.º 4
0
def _validate_yaml_import_group(group, yaml_file):
    """Validate group in clowder loaded from yaml file with import"""

    _validate_type_dict(group, 'group', yaml_file)

    if not group:
        error = fmt.invalid_entries_error('group', group, yaml_file)
        raise ClowderError(error)

    if 'name' not in group:
        error = fmt.missing_entry_error('name', 'group', yaml_file)
        raise ClowderError(error)
    _validate_type_str(group['name'], 'name', yaml_file)
    del group['name']

    if not group:
        error = fmt.invalid_entries_error('group', group, yaml_file)
        raise ClowderError(error)

    if 'projects' in group:
        _validate_yaml_projects(group['projects'], yaml_file, is_import=True)
        del group['projects']

    if 'recursive' in group:
        _validate_type_bool(group['recursive'], 'recursive', yaml_file)
        del group['recursive']

    if 'ref' in group:
        _validate_type_str(group['ref'], 'ref', yaml_file)
        if not _valid_ref_type(group['ref']):
            error = fmt.invalid_ref_error(group['ref'], yaml_file)
            raise ClowderError(error)
        del group['ref']

    if 'remote' in group:
        _validate_type_str(group['remote'], 'remote', yaml_file)
        del group['remote']

    if 'source' in group:
        _validate_type_str(group['source'], 'source', yaml_file)
        del group['source']

    if 'depth' in group:
        _validate_type_depth(group['depth'], yaml_file)
        del group['depth']

    if 'timestamp_author' in group:
        _validate_type_str(group['timestamp_author'], 'timestamp_author', yaml_file)
        del group['timestamp_author']

    if group:
        error = fmt.invalid_entries_error('group', group, yaml_file)
        raise ClowderError(error)
Ejemplo n.º 5
0
def _validate_yaml_import_defaults(defaults, yaml_file):
    """Validate clowder.yaml defaults with an import"""

    _validate_type_dict(defaults, 'defaults', yaml_file)
    if 'recursive' in defaults:
        _validate_type_bool(defaults['recursive'], 'recursive', yaml_file)
        del defaults['recursive']

    if 'ref' in defaults:
        _validate_type_str(defaults['ref'], 'ref', yaml_file)
        if not _valid_ref_type(defaults['ref']):
            error = fmt.invalid_ref_error(defaults['ref'], yaml_file)
            raise ClowderError(error)
        del defaults['ref']

    if 'remote' in defaults:
        _validate_type_str(defaults['remote'], 'remote', yaml_file)
        del defaults['remote']

    if 'source' in defaults:
        _validate_type_str(defaults['source'], 'source', yaml_file)
        del defaults['source']

    if 'depth' in defaults:
        _validate_type_depth(defaults['depth'], yaml_file)
        del defaults['depth']

    if 'timestamp_author' in defaults:
        _validate_type_str(defaults['timestamp_author'], 'timestamp_author', yaml_file)
        del defaults['timestamp_author']

    if defaults:
        error = fmt.invalid_entries_error('defaults', defaults, yaml_file)
        raise ClowderError(error)
Ejemplo n.º 6
0
def validate_yaml_import(yaml_file):
    """Validate clowder.yaml with an import"""

    parsed_yaml = parse_yaml(yaml_file)
    _validate_type_dict(parsed_yaml, fmt.yaml_file('clowder.yaml'), yaml_file)

    if 'import' not in parsed_yaml:
        error = fmt.missing_entry_error('import', fmt.yaml_file('clowder.yaml'), yaml_file)
        raise ClowderError(error)
    _validate_type_str(parsed_yaml['import'], 'import', yaml_file)
    del parsed_yaml['import']

    if not parsed_yaml:
        error = fmt.empty_yaml_error(yaml_file)
        raise ClowderError(error)

    if 'defaults' in parsed_yaml:
        _validate_yaml_import_defaults(parsed_yaml['defaults'], yaml_file)
        del parsed_yaml['defaults']

    if 'sources' in parsed_yaml:
        _validate_yaml_sources(parsed_yaml['sources'], yaml_file)
        del parsed_yaml['sources']

    if 'groups' in parsed_yaml:
        _validate_yaml_import_groups(parsed_yaml['groups'], yaml_file)
        del parsed_yaml['groups']

    if parsed_yaml:
        error = fmt.invalid_entries_error(fmt.yaml_file('clowder.yaml'), parsed_yaml, yaml_file)
        raise ClowderError(error)
Ejemplo n.º 7
0
def _validate_yaml_groups(groups, yaml_file):
    """Validate groups in clowder loaded from yaml file"""

    _validate_type_list(groups, 'groups', yaml_file)

    if not groups:
        error = fmt.invalid_entries_error('groups', groups, yaml_file)
        raise ClowderError(error)

    for group in groups:
        _validate_yaml_group(group, yaml_file)
Ejemplo n.º 8
0
def _validate_yaml_projects(projects, yaml_file, is_import):
    """Validate projects in clowder loaded from yaml file"""

    _validate_type_list(projects, 'projects', yaml_file)
    if not projects:
        error = fmt.invalid_entries_error('projects', projects, yaml_file)
        raise ClowderError(error)

    for project in projects:
        if is_import:
            _validate_yaml_import_project(project, yaml_file)
        else:
            _validate_yaml_project(project, yaml_file)
Ejemplo n.º 9
0
def _validate_yaml_fork(fork, yaml_file):
    """Validate fork in clowder loaded from yaml file"""

    _validate_type_dict(fork, 'fork', yaml_file)

    if not fork:
        error = fmt.invalid_entries_error('fork', fork, yaml_file)
        raise ClowderError(error)

    if 'name' not in fork:
        error = fmt.missing_entry_error('name', 'fork', yaml_file)
        raise ClowderError(error)
    _validate_type_str(fork['name'], 'name', yaml_file)
    del fork['name']

    if 'remote' not in fork:
        error = fmt.missing_entry_error('remote', 'fork', yaml_file)
        raise ClowderError(error)
    _validate_type_str(fork['remote'], 'remote', yaml_file)
    del fork['remote']

    if fork:
        error = fmt.invalid_entries_error('fork', fork, yaml_file)
        raise ClowderError(error)