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
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) }
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
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 }