forked from kemalbayram61/Python-Project-Visualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
determining_relationships.py
158 lines (126 loc) · 4.3 KB
/
determining_relationships.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import description_objects
import parse_objects
import description_objects
"""
summary
- relationships are standardized as follows
relation = {source: "source_id", destination: "destination_id", relationship_type: "relationship_type"}
- nodes are standardized as follows
node = {id:"id","Name: "name" type: "type", references: "imported modules names" "}
created: 27.05.2020 by [email protected]
"""
class CreateNetwork:
nodes = []
edges = []
objects = []
project_name = ""
def __init__(self,project):
self.project = project
self.project_name = project.getName()
def determiningNodesByModules(self):
self.nodes = []
modules = self.project.getModules()
node ={"id": 1,"name": "module_name", "type": "module_type","references": "imported modules names"}
idCounter = 0
for mdl in modules:
module = mdl.getModule()
node["id"] = idCounter
node["name"] = module.getName()
node["type"] = "module"
node["references"] = module.getImportedModules()
self.nodes.append(node)
idCounter = idCounter + 1
def determiningNodesByClass(self):
self.nodes =[]
modules = self.project.getModules()
node = {"id": 1, "name": "module_name", "type": "module_type", "references": "imported modules names"}
idCounter = 0
modulClasses = []
modulReferences = []
referenceNames = []
for mdl in modules:
module = mdl.getModule()
modulClasses = module.getClasses()
for cls in modulClasses:
node["id"] = idCounter
node["name"] = cls.getName()
node["type"] = "class"
node["references"] = cls.getImportedModules()
self.nodes.append(node)
idCounter = idCounter + 1
def getNodes(self):
return self.nodes
def getEdges(self):
return self.edges
dize ="""
class Classes:
functions=[]
body=None
name=None
importedModules = []
def __init__(self,name,functions,body,importedModules):
self.name = name
self.functions=functions
self.body=body
self.importedModules = importedModules
def getFunctions(self):
return self.functions
def getBody(self):
return self.body
def getJson(self):
jsonDefinition=""
if(self.name!=None):
jsonDefinition+=self.name+"{"
else:
jsonDefinition+="main{"
jsonDefinition+="functions{"
if(len(self.functions)>0):
for i in range(len(self.functions)-1):
jsonDefinition+=self.functions[i].getJson()+","
jsonDefinition+=str(self.functions[len(self.functions)-1])+"}"
else:
jsonDefinition+="},"
jsonDefinition+="body{"+self.body.getJson()+"}"
return jsonDefinition
def getImportedModules(self):
return self.importedModules
class Classes2:
functions=[]
body=None
name=None
importedModules = []
def __init__(self,name,functions,body,importedModules):
self.name = name
self.functions=functions
self.body=body
self.importedModules = importedModules
def getFunctions(self):
return self.functions
def getBody(self):
return self.body
def getJson(self):
jsonDefinition=""
if(self.name!=None):
jsonDefinition+=self.name+"{"
else:
jsonDefinition+="main{"
jsonDefinition+="functions{"
if(len(self.functions)>0):
for i in range(len(self.functions)-1):
jsonDefinition+=self.functions[i].getJson()+","
jsonDefinition+=str(self.functions[len(self.functions)-1])+"}"
else:
jsonDefinition+="},"
jsonDefinition+="body{"+self.body.getJson()+""
return jsonDefinition
def getImportedModules(self):
return self.importedModules
"""
project = parse_objects.ParseProject("proje1")
project.addModul("modules1",dize)
project = project.getProject()
network = CreateNetwork(project)
network.determiningNodesByClass()
nodes = network.getNodes()
for node in nodes:
print(node)