示例#1
0
def color_diff():
    global colors
    for n in graphiti.get_node_ids():
        s = graphiti.get_node_attribute(n, 'diffstatus')
        graphiti.set_node_attribute(n, "graphiti:space:color", "vec3", colors[s])
    for e in graphiti.get_edge_ids():
        s = graphiti.get_edge_attribute(e, 'diffstatus')
        try:
            graphiti.set_edge_attribute(e, "graphiti:space:color", "vec3", colors[s])
        except KeyError:
            print("edge: {}".format(e))
            print("diffstatus: {}".format(s))
            sys.exit(-1)
示例#2
0
def color_diff():
    global colors
    for n in graphiti.get_node_ids():
        s = graphiti.get_node_attribute(n, 'diffstatus')
        graphiti.set_node_attribute(n, "graphiti:space:color", "vec3",
                                    colors[s])
    for e in graphiti.get_edge_ids():
        s = graphiti.get_edge_attribute(e, 'diffstatus')
        try:
            graphiti.set_edge_attribute(e, "graphiti:space:color", "vec3",
                                        colors[s])
        except KeyError:
            print("edge: {}".format(e))
            print("diffstatus: {}".format(s))
            sys.exit(-1)
示例#3
0
def regex_map(expression, attribute, node_flag, edge_flag, f, translate = True):

    if translate:
        expression = fnmatch.translate(expression)
    r = re.compile(expression)
    if r is None:
        print("Invalid expression : <" + expression + "> !")
        return            

    if node_flag:
        for nid in graphiti.get_node_ids():
            value = None

            if attribute == "label":
                value = graphiti.get_node_label(nid)
            elif attribute == "mark":
                value = graphiti.get_node_mark(nid)
            elif attribute == "weight":
                value = graphiti.get_node_weight(nid)
            else:
                value = graphiti.get_node_attribute(nid, attribute)

            if value is None:
                f("node", nid, None)
            else:
                f("node", nid, r.match(str(value)))

    if edge_flag:
        for eid in graphiti.get_edge_ids():
            value = None

            if attribute == "node1":
                value = graphiti.get_edge_node1(eid)
            elif attribute == "node2":
                value = graphiti.get_edge_node2(eid)
            else:
                value = graphiti.get_edge_attribute(eid, attribute)

            if value is None:
                f("edge", eid, None)
            else:
                value_str = str(value)
                f("edge", eid, r.match(value_str))
示例#4
0
def save_json(filename):
    
    graph = {}
    graph["meta"] = dict()
    graph["nodes"] = list()
    graph["edges"] = list()

    global node_attributes
    global edge_attributes
    
    for id in graphiti.get_node_ids():
        node = dict()
        node["id"] = id
        node["label"] = graphiti.get_node_label(id)

        for attribute in node_attributes:
            name = attribute['name']
            value = graphiti.get_node_attribute(id, name)
            if value is None:
                continue
            node[name] = value

        graph["nodes"].append(node)

    for id in graphiti.get_edge_ids():
        edge = dict()
        edge["id"] = id
        edge["src"] = graphiti.get_edge_node1(id)
        edge["dst"] = graphiti.get_edge_node2(id)

        for attribute in edge_attributes:
            name = attribute['name']
            value = graphiti.get_edge_attribute(id, name)
            if value is None:
                continue
            edge[name] = value

        graph["edges"].append(edge)

    with open(filename, 'w') as outfile:
        json.dump(graph, outfile, indent=True, sort_keys=True)