Esempio n. 1
0
def view(request):
    session = DBSession()
    ro, view_params = view_init_min(request, session)

    view_params['description'] = Markup(ro.html_description())

    prov_def = ro.repr_json(full=True)
    data = {}
    workflow = ROWorkflow.get(session, prov_def['workflow'])
    if workflow is not None:
        store = {}
        workflow_def = workflow.repr_json(full=True)
        for node_def in workflow_def['nodes']:
            nid = node_def['id']
            wnode = ROWorkflowNode.get(session, nid)
            if wnode is None:
                pass
            else:
                store[nid] = wnode.repr_json(full=True)
                store[nid]['url'] = request.route_url('ro_view_home', uid=nid)

        txt, viewbox = svg.export_workflow(workflow_def, store, (800, 600))
        view_params['svg_repr'] = txt
        view_params['svg_viewbox'] = json.dumps(viewbox)

        prov = prov_def
        fmt_data = {}
        for data_obj in prov['data']:
            dtype = data_obj['type']
            if dtype == "ref":  # internally used to reference another RO
                url = request.route_url('ro_view_home', uid=data_obj["value"])
                val = '<p><a href="%s">link to RO</a></p>' % url
            elif dtype == "int":
                val = "<p>%d</p>" % data_obj["value"]
            elif dtype == "str":
                val = "<p>%s</p>" % data_obj["value"]
            elif dtype == "url":
                val = "<p>%s</p>" % data_obj["value"]
            elif dtype in ("image", "IImage"):
                img_data = data_obj["value"].replace("\n", "")
                val = '<img src="data:image/png;base64,%s" />' % img_data
            else:
                val = "<p>%s</p>" % json.dumps(data_obj["value"])
            fmt_data[data_obj['id']] = (dtype, val)

        for pexec in prov['executions']:
            nid = pexec['node']
            for port in pexec['inputs']:
                if port['data'] is not None:
                    key = "wkf_node_%d_input_%s" % (nid, port['port'])
                    data[key] = fmt_data[port['data']]

            for port in pexec['outputs']:
                if port['data'] is not None:
                    key = "wkf_node_%d_output_%s" % (nid, port['port'])
                    data[key] = fmt_data[port['data']]

    view_params['wkf_data'] = data

    return view_params
Esempio n. 2
0
def view(request):
    session = DBSession()
    ro, view_params = view_init_min(request, session)

    view_params['description'] = Markup(ro.html_description())

    store = {}
    workflow_def = ro.repr_json(full=True)
    for node_def in workflow_def['nodes']:
        nid = node_def['id']
        wnode = ROWorkflowNode.get(session, nid)
        if wnode is None:
            pass
        # elif wnode.category == "alias":
        #     wnode = resolve_target(session, wnode)
        #     store[nid] = wnode.load_definition()
        #     store[nid]['url'] = request.route_url('project_content_alias_view_item', pid=wnode.project, cid=nid)
        else:
            store[nid] = wnode.repr_json(full=True)
            store[nid]['url'] = request.route_url('ro_view_home', uid=nid)

    for nid, node in store.items():
        for port in node['inputs'] + node['outputs']:
            iid = port['interface']
            iface = ROInterface.get(session, iid)
            if iface is None:
                pass
            else:
                store[iid] = iface.repr_json(full=True)
                store[iid]['url'] = request.route_url('ro_view_home', uid=iid)

    txt, viewbox = svg.export_workflow(workflow_def, store, (800, 600))
    view_params['svg_repr'] = txt
    view_params['svg_viewbox'] = json.dumps(viewbox)

    return view_params
Esempio n. 3
0
def main(session, user, container):
    """Create workflow related projects.

    Args:
        session (DBSession):
        user (User): owner of created project
        container (ROContainer): top level container

    Returns:
        None
    """
    # default interfaces for openalea
    roa = ROContainer()
    roa.init(session, dict(owner=user.id, name="openalea.interfaces"))

    top = ROContainer()
    top.init(session, dict(owner=user.id, name="openalea", contents=[roa]))

    itrans = {}
    for iname in ("IBool", "ICodeStr", "IColor", "IData", "IDateTime",
                  "IDict", "IDirStr",
                  "IEnumStr", "IFileStr", "IFloat",
                  "IFunction", "IImage", "IInt", "IRef", "IRGBColor",
                  "ISequence", "ISlice", "IStr", "ITextStr",
                  "ITuple", "ITuple3"):
        standard_interface = get_interface_by_name(session, iname[1:].lower())
        if standard_interface is not None:
            ancestors = [standard_interface.id]
        else:
            ancestors = []

        roi = ROInterface()
        roi.init(session, dict(owner=user.id, name=iname, ancestors=ancestors))

        ROLink.connect(session, roa.id, roi.id, "contains")
        itrans[iname] = roi.id

    roc = ROContainer()
    roc.init(session, dict(owner=user.id, name="nodelib"))
    ROLink.connect(session, container.id, roc.id, 'contains')

    ndefs = []
    for i in range(3):
        node_def = dict(name="read%d" % i,
                        description="toto was here",
                        owner=user.id,
                        function="testio:read",
                        inputs=[dict(name="in1", interface=itrans["IInt"],
                                     default="0", description="counter"),
                                dict(name="in2", interface=itrans["IStr"],
                                     default="a", description="unit")],
                        outputs=[dict(name="ret", interface=itrans["IInt"],
                                      description="important result")])

        rown = ROWorkflowNode()
        rown.init(session, node_def)
        ndefs.append(rown)

        ROLink.connect(session, roc.id, rown.id, "contains")

    # alias = ContentItem.create(session, uuid1().hex, "alias", nodelib)
    # alias.author = "revesansparole"
    # alias.name = ndefs[2]['id']

    workflow_def = dict(name="sample_workflow",
                        description="trying some stuff",
                        owner="revesansparole",
                        nodes=[dict(id=ndefs[0].id, label="node1",
                                    x=-50, y=-80),
                               dict(id=ndefs[1].id, label=None,
                                    x=50, y=-80),
                               dict(id=ndefs[2].id, label=None,
                                    x=0, y=0),
                               dict(id='4094cf5a490711e6aa4cd4bed973e64a',
                                    label="fail",
                                    x=0, y=80)],
                        links=[dict(source=0, source_port="ret",
                                    target=2, target_port="in1"),
                               dict(source=1, source_port="ret",
                                    target=2, target_port="in2"),
                               dict(source=2, source_port="ret",
                                    target=3, target_port="in")])

    row = ROWorkflow()
    row.init(session, workflow_def)
    ROLink.connect(session, roc.id, row.id, "contains")

    roc = ROContainer()
    roc.init(session, dict(owner=user.id, name="provenance"))
    ROLink.connect(session, container.id, roc.id, 'contains')

    with open("seeweb/scripts/gallery/graph_pulse.png", 'rb') as f:
        graph_pulse = b64encode(f.read())

    with open("seeweb/scripts/sphere.json", 'r') as f:
        sphere = json.load(f)

    data = [dict(id=uuid1().hex, type="ref", value=itrans["IInt"]),
            dict(id=uuid1().hex, type="int", value=10),
            dict(id=uuid1().hex, type="str", value="Killroy was here"),
            dict(id=uuid1().hex, type="image", value=graph_pulse),
            dict(id=uuid1().hex, type="scene3d", value=sphere)
            ]

    prov_def = dict(name="sample_provenance",
                    description="trying some stuff",
                    owner=user.id,
                    workflow=row.id,
                    time_init=10,
                    time_end=14,
                    data=data,
                    parameters=[dict(node=0, port="in1", data=data[0]['id']),
                                dict(node=0, port="in2", data=data[2]['id'])
                                ],
                    executions=[
                        dict(node=0, time_init=10, time_end=11,
                             inputs=[
                                 {"port": "in1", "data": data[0]['id']},
                                 {"port": "in2", "data": data[2]['id']}
                             ],
                             outputs=[
                                 {"port": "ret", "data": data[1]['id']}
                             ]),
                        dict(node=1, time_init=10, time_end=11,
                             inputs=[
                                 {"port": "in1", "data": data[0]['id']}
                             ],
                             outputs=[
                                 {"port": "ret", "data": data[3]['id']}
                             ]),
                        dict(node=2, time_init=12, time_end=13,
                             inputs=[
                                 {"port": "in1", "data": data[1]['id']},
                                 {"port": "in2", "data": data[3]['id']}
                             ],
                             outputs=[
                                 {"port": "ret", "data": data[4]['id']}
                             ])
                    ]
                    )

    with open("../prov.wkf", 'w') as f:
        json.dump(prov_def, f)

    rop = ROWorkflowProv()
    rop.init(session, prov_def)
    ROLink.connect(session, roc.id, rop.id, "contains")