Exemplo n.º 1
0
def _load_component_link(rec, context):
    frm = list(map(context.object, rec['frm']))
    to = list(map(context.object, rec['to']))[0]
    using = context.object(rec['using'])
    inverse = context.object(rec['inverse'])
    result = ComponentLink(frm, to, using, inverse)
    result.hidden = rec['hidden']
    return result
Exemplo n.º 2
0
Arquivo: state.py Projeto: rguter/glue
def _load_component_link(rec, context):
    frm = list(map(context.object, rec["frm"]))
    to = list(map(context.object, rec["to"]))[0]
    using = context.object(rec["using"])
    inverse = context.object(rec["inverse"])
    result = ComponentLink(frm, to, using, inverse)
    result.hidden = rec["hidden"]
    return result
Exemplo n.º 3
0
def parse_links(dc, links):
    from glue.core.link_helpers import MultiLink
    from glue.core import ComponentLink

    data = dict((d.label, d) for d in dc)
    result = []

    def find_cid(s):
        dlabel, clabel = s.split('.')
        d = data[dlabel]
        c = d.find_component_id(clabel)
        if c is None:
            raise ValueError("Invalid link (no component named %s)" % s)
        return c

    for link in links:
        f, t = link[0:2]  # from and to component names
        u = u2 = None
        if len(link) >= 3:  # forward translation function
            u = link[2]
        if len(link) == 4:  # reverse translation function
            u2 = link[3]

        # component names -> component IDs
        if isinstance(f, str):
            f = [find_cid(f)]
        else:
            f = [find_cid(item) for item in f]

        if isinstance(t, str):
            t = find_cid(t)
            result.append(ComponentLink(f, t, u))
        else:
            t = [find_cid(item) for item in t]
            result += MultiLink(f, t, u, u2)

    return result