Beispiel #1
0
def suggest_for_files(gear, files, context=None):

    invocation_schema = get_invocation_schema(gear)
    schemas = {}
    suggested_inputs = {}

    for x in gear['gear']['inputs']:
        input_ = gear['gear']['inputs'][x]
        if input_.get('base') == 'context':
            if x in context:
                suggested_inputs[x] = [{
                    'base': 'context',
                    'found': True,
                    'value': context[x]['value']
                }]
            else:
                suggested_inputs[x] = [{'base': 'context', 'found': False}]
        elif input_.get('base') == 'file':
            schema = gear_tools.isolate_file_invocation(invocation_schema, x)
            schemas[x] = Draft4Validator(schema)

    for input_name, schema in schemas.iteritems():
        suggested_inputs[input_name] = []
        for f in files:
            if schema.is_valid(f):
                suggested_inputs[input_name].append({
                    'base': 'file',
                    'name': f.get('name')
                })

    return suggested_inputs
Beispiel #2
0
def suggest_container(gear, cont_name, cid):
    """
    Given a container reference, suggest files that would work well for each input on a gear.
    """

    root = ContainerStorage.factory(cont_name).get_container(
        cid, projection={'permissions': 0}, get_children=True)
    root['analyses'] = ContainerStorage.factory('analyses').get_analyses(
        cont_name, cid, False)

    invocation_schema = get_invocation_schema(gear)

    schemas = {}
    for x in gear['gear']['inputs']:
        schema = gear_tools.isolate_file_invocation(invocation_schema, x)
        schemas[x] = Draft4Validator(schema)

    # It would be nice to have use a visitor here instead of manual key loops.
    for acq in root.get('acquisitions', []):
        for f in acq.get('files', []):
            f['suggested'] = {}
            for x in schemas:
                f['suggested'][x] = schemas[x].is_valid(f)

    for analysis in root.get('analyses', []):
        files = analysis.get('files', [])
        files[:] = [x for x in files if x.get('output')]
        for f in files:
            f['suggested'] = {}
            for x in schemas:
                f['suggested'][x] = schemas[x].is_valid(f)
        analysis['files'] = files

    return root
Beispiel #3
0
def suggest_for_files(gear, files):

    invocation_schema = get_invocation_schema(gear)
    schemas = {}
    for x in gear['gear']['inputs']:
        schema = gear_tools.isolate_file_invocation(invocation_schema, x)
        schemas[x] = Draft4Validator(schema)

    suggested_files = {}
    for input_name, schema in schemas.iteritems():
        suggested_files[input_name] = []
        for f in files:
            if schema.is_valid(f):
                suggested_files[input_name].append(f.get('name'))

    return suggested_files
Beispiel #4
0
def suggest_for_files(gear, files):

    invocation_schema = get_invocation_schema(gear)
    schemas = {}
    for x in gear['gear']['inputs']:
        schema = gear_tools.isolate_file_invocation(invocation_schema, x)
        schemas[x] = Draft4Validator(schema)

    suggested_files = {}
    log.debug(schemas)
    for input_name, schema in schemas.iteritems():
        suggested_files[input_name] = []
        for f in files:
            if schema.is_valid(f):
                suggested_files[input_name].append(f.get('name'))

    return suggested_files
Beispiel #5
0
def add_suggest_info_to_files(gear, files):
    """
    Given a list of files, add information to each file that details those that would work well for each input on a gear.
    """

    invocation_schema = get_invocation_schema(gear)

    schemas = {}
    for x in gear['gear']['inputs']:
        schema = gear_tools.isolate_file_invocation(invocation_schema, x)
        schemas[x] = Draft4Validator(schema)

    for f in files:
        f['suggested'] = {}
        for x in schemas:
            f['suggested'][x] = schemas[x].is_valid(f)

    return files
Beispiel #6
0
def add_suggest_info_to_files(gear, files):
    """
    Given a list of files, add information to each file that details those that would work well for each input on a gear.
    """

    invocation_schema = get_invocation_schema(gear)

    schemas = {}
    for x in gear['gear']['inputs']:
        input_ = gear['gear']['inputs'][x]
        if input_.get('base') == 'file':
            schema = gear_tools.isolate_file_invocation(invocation_schema, x)
            schemas[x] = Draft4Validator(schema)

    for f in files:
        f['suggested'] = {}
        for x in schemas:
            f['suggested'][x] = schemas[x].is_valid(f)

    return files