Ejemplo n.º 1
0
def rebase_input_path(constructor, value, base):
    if isinstance(constructor, ObjectConstructor):

        def do_rebase_obj(val):
            ret = {}
            for k, v in six.iteritems(val):
                c = constructor.properties.get(k)
                rebased = None
                if c:
                    rebased = rebase_input_path(constructor.properties[k], v, base)
                if rebased:
                    ret[k] = rebased
            return ret

        return map_rec_list(do_rebase_obj, value)

    if isinstance(constructor, ArrayConstructor):
        ret = []
        for item in value:
            rebased = rebase_input_path(constructor.item_constructor, item, base)
            if rebased:
                ret.append(rebased)
        return ret

    def do_rebase(v):
        if isinstance(v, dict):
            v['path'] = to_abspath(v['path'], base)
            return v
        return to_abspath(v, base)

    if isinstance(constructor, FileConstructor):
        return map_rec_list(do_rebase, value)

    return None
Ejemplo n.º 2
0
def get_inputs(app, args):

    def get_arg(name):
        return args.get('--' + name) or args.get(name)

    return {
        input.id: map_rec_list(input.constructor, get_arg(input.id))
        for input in app.inputs.io
        if get_arg(input.id)
    }
Ejemplo n.º 3
0
def construct_files(val, schema):
    if schema.type == 'array':
        return [construct_files(e, schema.items) for e in val]

    if schema.type == 'record':
        if schema.name == 'File':
            return map_rec_list(File, val) if val else val
        else:
            ret = {}
            for fld in schema.fields:
                ret[fld.name] = construct_files(val.get(fld.name), fld.type)
            return ret

    if schema.type == 'union':
        for s in schema.schemas:
            if validate(s, val):
                return construct_files(val, s)
    return val
Ejemplo n.º 4
0
def construct_files(val, schema):
    if schema.type == 'array':
        return [construct_files(e, schema.items) for e in val]

    if schema.type == 'record':
        if schema.name == 'File':
            return map_rec_list(File, val) if val else val
        else:
            ret = {}
            for fld in schema.fields:
                ret[fld.name] = construct_files(val.get(fld.name), fld.type)
            return ret

    if schema.type == 'union':
        for s in schema.schemas:
            if validate(s, val):
                return construct_files(val, s)
    return val
Ejemplo n.º 5
0
 def construct(defs, vals):
     return {
         input.id: map_rec_list(input.constructor, vals.get(input.id))
         for input in defs
         if vals.get(input.id) is not None
     }