Ejemplo n.º 1
0
        fileHandle = open(os.path.join(getPysqgIncludeDir(), file), 'r')
        jsonSqg = json.load(fileHandle)
        fileHandle.close()
        for arrayListType in jsonSqg.keys(): 
            if arrayListType not in ("name", "include", "parents", "sharedVariables"): #This is very hacky, it would be nice to have a clean way to know which sqg defined which array list.
                arrayList = InMemoryArrayList(type=arrayListType)
                arrayNode = i
                i = i+1
                typeStringsToNodeNamesAndArrays[arrayListType] = (arrayNode, arrayList)
                arrayLists.addDict({ "nodeName":arrayNode, "name":arrayListType, "arrayNames":" ".join(arrayList.getArrayNames()), "arrayTypes":" ".join(arrayList.getArrayTypes()) })
                graphEdges.addDict({ "outNode":graphNode, "inNode":arrayNode })

#Add in the inherits edges
for typeString in typeStringsToNodeNamesAndArrays.keys():
    arrayNode, arrayList = typeStringsToNodeNamesAndArrays[typeString]
    if arrayList.getInherits() != None:
        parentArrayNode, parentArrayList = typeStringsToNodeNamesAndArrays[arrayList.getInherits().getType()]
        inheritEdges.addDict({ "outNode":parentArrayNode, "inNode":arrayNode })


#We're done
print makeJsonSqgFromSqg(inheritanceGraph)

#Here we dump a dot version of the graph, using the networkX interface.
nxGraph, nxSubgraphs = networkxWrite(inheritanceGraph)
for node in nxGraph.nodes():
    nodeAtts = nxGraph.node[node]
    label = "%s [%s]" % (nodeAtts["name"], nodeAtts["type"])
    if nodeAtts["type"] == "arrayLists":
        arrayTypes = nodeAtts["arrayTypes"].split()
        arrayNames = nodeAtts["arrayNames"].split()