forked from rmeloca/EcosystemsAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateDOTVersionIrregularDependenciesGraph.py
More file actions
70 lines (66 loc) · 2.23 KB
/
generateDOTVersionIrregularDependenciesGraph.py
File metadata and controls
70 lines (66 loc) · 2.23 KB
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
import sys
from ecosystemDataManager.ecosystemDataManager import EcosystemDataManager
VISITED = []
FILE = None
"""
Write in file the struct to by read in DOT generator
To generate DOT in PDF use the comand: dot -Tpdf > file.pdf
"""
def generate(version):
if version in VISITED:
return
VISITED.append(version)
if not version.getDatetime():
return
color = "red" if version.isIrregular() == True else "orange" if version.isAffected() == True else "blue"
licenses = ", ".join([str(l) for l in version.getLicenses()])
if not licenses:
licenses = "none"
FILE.write("\"" + str(version) + "\\n" + licenses + "\"" + "[color="+color+"]" + ";")
for d in version.getDependencies():
inV = d.getInVersion()
if inV.isAffected() == False and inV.isIrregular() == False and d.isIrregular() == False:
continue
outV = d.getOutVersion()
outL = ", ".join([str(l) for l in outV.getLicenses()])
if not outL:
outL = "none"
inL = ", ".join([str(l) for l in inV.getLicenses()])
if not inL:
inL = "none"
color = "red" if d.isIrregular() == True else "green" if d.isIrregular() == False else "gray"
FILE.write("\"" + str(outV) + "\\n" + outL + "\"" + "->" + "\"" + str(inV) + "\\n" + inL + "\"" + "[color=" + color + "]" + ";")
generate(inV)
"""
Generate a directed graphs from package of ecosystem
"""
def generateDot(version):
FILE.write("digraph graphname {")
generate(version)
FILE.write("}")
if __name__ == '__main__':
package = None
version = None
if len(sys.argv) < 2:
print("Usage:", sys.argv[0], "<ecosystem> [<package> [<version>]]")
sys.exit(1)
if len(sys.argv) > 2:
package = sys.argv[2]
if len(sys.argv) > 3:
version = sys.argv[3]
ecosystem = sys.argv[1]
ecosystemDataManager = EcosystemDataManager(ecosystem)
if package:
package = ecosystemDataManager.getPackage(package)
else:
print("no package provided. Retrieving Most Popular")
package = ecosystemDataManager.getMostPopularPackages(1)[0]
if version:
version = package.getVersion(version)
else:
print("no version provided. Retrieving Most Popular")
version = package.getMostPopularVersions(1)[0]
print("generating DOT to", version)
with open(ecosystem + "_" + package.getName() + "_" + version.getName() + ".dot", "w") as FILE:
generateDot(version)
print("done")