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

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

    store = {}
    node_def = ro.repr_json(full=True)
    for port in chain(node_def['inputs'], node_def['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_node(node_def, store, (800, 300))
    view_params['svg_repr'] = txt
    view_params['svg_viewbox'] = json.dumps(viewbox)

    return view_params
Exemplo n.º 2
0
def data_type(session, interface):
    """Find a RO type that implements this interface
    or its closest ancestor.

    Notes: default to 'data'

    Args:
        session (Session): previously open session
        interface (str): uid of interface

    Returns:
        (str): name of RO type
    """
    front = [interface]
    while len(front) > 0:
        uid = front.pop(0)
        if uid in data_factory:
            return data_factory[uid]

        roi = ROInterface.get(session, uid)
        front.extend(roi.ancestors())

    return "data"
Exemplo n.º 3
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
Exemplo n.º 4
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")
Exemplo n.º 5
0
def main(session, user, container):
    """Create a project that contains different types of data

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

    Returns:
        None
    """
    # register common data interfaces
    roc = ROContainer()
    roc.init(
        session,
        dict(
            id="81c69a8558a311e6afb6d4bed973e64a",
            owner=user.id,
            name="interfaces",
            public=True,
            description="Store commonly used interfaces",
        ),
    )

    roi = ROInterface()
    roi.init(
        session,
        dict(
            id=ROData.implements,
            owner=user.id,
            name="any",
            public=True,
            description="Interface used for data that don't " "have a specific interface",
        ),
    )
    ROLink.connect(session, roc.id, roi.id, "contains")

    ropy = ROInterface()
    ropy.init(session, dict(id="dc5b10c858a611e6afb6d4bed973e64a", owner=user.id, name="pyobj", public=True))
    ROLink.connect(session, roc.id, ropy.id, "contains")

    schema = dict(
        title="Interface for data of type 'string'", description="Just a simple chain of characters", type="string"
    )

    roi = ROInterface()
    roi.init(
        session,
        dict(
            id="006bca4c58a311e6afb6d4bed973e64a",
            owner=user.id,
            name="string",
            public=True,
            schema=cvt_schema(schema),
            ancestors=[ropy.id],
        ),
    )
    ROLink.connect(session, roc.id, roi.id, "contains")

    sid = roi.id
    for name in ("code", "path", "ref", "text"):
        roi = ROInterface()
        roi.init(session, dict(owner=user.id, name=name, public=True, ancestors=[sid]))
        ROLink.connect(session, roc.id, roi.id, "contains")

    schema = dict(title="Interface for data of type 'number'", description="Just a simple number", type="number")

    roi = ROInterface()
    roi.init(
        session,
        dict(
            id="c7f6a30a58a511e6afb6d4bed973e64a",
            owner=user.id,
            name="number",
            public=True,
            schema=cvt_schema(schema),
            ancestors=[ropy.id],
        ),
    )
    ROLink.connect(session, roc.id, roi.id, "contains")

    sid = roi.id
    for name in ("complex", "int", "float"):
        roi = ROInterface()
        roi.init(session, dict(owner=user.id, name=name, public=True, ancestors=[sid]))
        ROLink.connect(session, roc.id, roi.id, "contains")

    rgba_schema = dict(
        title="Interface for color of type rgba",
        description="Just a simple array of rgba quadruplets",
        type="array",
        minLength=4,
        maxLength=4,
        items=dict(type="int"),
    )

    roi = ROInterface()
    roi.init(
        session,
        dict(
            id="256203e058b911e6afb6d4bed973e64a",
            owner=user.id,
            name="rgba",
            public=True,
            schema=cvt_schema(rgba_schema),
            ancestors=[],
        ),
    )
    ROLink.connect(session, roc.id, roi.id, "contains")

    schema = dict(
        title="Interface for data of type 2D images",
        description="Just a simple 2d array of rgba quadruplets",
        type="array",
        minLength=1,
        items=dict(type="array", minLength=1, items=rgba_schema),
    )

    roi = ROInterface()
    roi.init(
        session,
        dict(id=ROImage.implements, owner=user.id, name="image", public=True, schema=cvt_schema(schema), ancestors=[]),
    )
    ROLink.connect(session, roc.id, roi.id, "contains")

    schema = dict(
        title="Interface for data of type 3D scenes",
        description="Json description of a 3D scene",
        type="array",
        minLength=1,
        items=dict(type="array", minLength=1, items=rgba_schema),
    )

    roi = ROInterface()
    roi.init(
        session,
        dict(
            id=ROScene3d.implements, owner=user.id, name="scene3d", public=True, schema=cvt_schema(schema), ancestors=[]
        ),
    )
    ROLink.connect(session, roc.id, roi.id, "contains")

    # create a sample project with some common data examples
    roc = ROContainer()
    roc.init(session, dict(id="0a73ad11596111e6a3a6d4bed973e64a", owner=user.id, name="data", ctype="project"))
    ROLink.connect(session, container.id, roc.id, "contains")

    # raw data
    rod = ROData()
    rod.init(session, dict(owner=user.id, name="test number", value=3.14159))
    ROLink.connect(session, roc.id, rod.id, "contains")

    with open("seeweb/ro/data/static/default_avatar.png", "rb") as f:
        value = b64encode(f.read())

    rod = ROData()
    rod.init(session, dict(owner=user.id, name="test data", value=value))
    ROLink.connect(session, roc.id, rod.id, "contains")

    # image
    with open("seeweb/ro/data/static/default_avatar.png", "rb") as f:
        value = b64encode(f.read())

    roi = ROImage()
    roi.init(
        session,
        dict(
            id="03faa88158bb11e6afb6d4bed973e64a",
            owner=user.id,
            name="test image",
            value=value,
            description="Sample image for testing purpose",
        ),
    )
    ROLink.connect(session, roc.id, roi.id, "contains")

    # scene3D
    with open("seeweb/scripts/scene.json", "r") as f:
        sc = json.load(f)

    rosc = ROScene3d()
    rosc.init(session, dict(owner=user.id, name="test scene", value=sc))
    ROLink.connect(session, roc.id, rosc.id, "contains")