-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphBuilder.py
149 lines (127 loc) · 4.83 KB
/
graphBuilder.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
import yaml
import os
import string
jobList = os.listdir("./jjb")
artifactList = []
scriptsUsed = []
scripList = os.listdir("./scripts")
test = []
for job in jobList:
if "job" in job or "libpvm" in job:
if "jenkins_jobs.ini" in job:
continue
f = open("./jjb/" + job, "r")
test = test + yaml.load(f)
graphOutput = 'digraph G {\n'
def getJobDependancies(i, graphOutput):
try:
currentJob = i["job-template"]["name"]
for j in i["job-template"]["publishers"]:
if "trigger-parameterized-builds" in j:
try:
for k in j["trigger-parameterized-builds"]:
try:
for l in k['project']:
graphOutput = graphOutput + ' "' + currentJob + '" -> "CADETS/bsd/{branch}/' + l + '";\n'
except:
continue
except:
continue
elif "trigger" in j:
try:
l = j["trigger"]["project"]
graphOutput = graphOutput + ' "' + currentJob + '" -> "' + l + '";\n'
except:
continue
for j in i["job-template"]["triggers"]:
try:
l = j["reverse"]["jobs"]
l = l.partition("/")
if l[len(l) - 1] == "":
l = l[0]
else:
l = l[len(l) - 1]
if ".." in l:
l = "CADETS" + l[2:]
graphOutput = graphOutput + ' "' + l + '" -> "' + currentJob + '";\n'
except:
continue
except:
return graphOutput
return graphOutput
def getDependanciesOnArtifacts(i, graphOutput):
try:
currentJob = i["job-template"]["name"]
for j in i["job-template"]["builders"]:
if "copyartifact" in j:
try:
parser = j["copyartifact"]['filter']
parser = string.split(parser, "/")
for part in parser:
subParser = string.split(part, ",")
for subPart in subParser:
if "." in subPart:
artifactList.append(subPart)
graphOutput = graphOutput + ' "' + subPart + '" -> "' + currentJob + '" [style = dashed];\n'
except:
continue
except:
return graphOutput
return graphOutput
def getDependanciesOnScripts(i, graphOutput):
try:
currentJob = i["job-template"]["name"]
for j in i["job-template"]["builders"]:
if "shell" in j:
try:
for script in scripList:
if script in j["shell"]:
scriptsUsed.append(script)
graphOutput = graphOutput + ' "' + script + '" -> "' + currentJob + '" [style = bold];\n'
except:
continue
except:
return graphOutput
return graphOutput
def getArtifactDependancies(i, graphOutput):
try:
currentJob = i["job-template"]["name"]
for j in i["job-template"]["publishers"]:
if "archive" in j:
try:
parser = j["archive"]['artifacts']
parser = string.split(parser, "/")
for part in parser:
subParser = string.split(part, ",")
for subPart in subParser:
if "." in subPart:
artifactList.append(subPart)
graphOutput = graphOutput + ' "' + currentJob + '" -> "' + subPart + '" [style = dashed];\n'
except:
continue
except:
return graphOutput
return graphOutput
for i in test:
graphOutput = getJobDependancies(i, graphOutput)
graphOutput = getDependanciesOnArtifacts(i, graphOutput)
graphOutput = getDependanciesOnScripts(i, graphOutput)
scriptsUsed = list(set(scriptsUsed))
artifactList = list(set(artifactList))
for i in test:
graphOutput = getArtifactDependancies(i, graphOutput)
for i in scriptsUsed:
scriptContents = open("./scripts/" + i, "r")
for art in artifactList:
for line in scriptContents:
if art in line:
graphOutput = graphOutput + ' "' + art + '" -> "' + i + '" [style = dashed];\n'
artifactList = list(set(artifactList))
for art in artifactList:
graphOutput = graphOutput + ' "' + art + '" [shape = rectangle];\n'
for script in scriptsUsed:
graphOutput = graphOutput + ' "' + script + '" [shape = diamond];\n'
graphOutput = graphOutput + "}"
output = open("graph.txt", "w")
output.write(graphOutput)
output.close()