-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgenerateGraph.py
More file actions
executable file
·56 lines (43 loc) · 1.33 KB
/
generateGraph.py
File metadata and controls
executable file
·56 lines (43 loc) · 1.33 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
#!/usr/bin/env python
from LogReader import *
from supybotParser import *
import sys
import re
import pygraphviz
def generateGraph(layout,filelist,outputimage):
reader=LogReader(filelist)
log, nicks = parseLog(reader)
print "Nicks: %s" % (", ".join(nicks))
#Prepare the graph
graph = {}
for nick in nicks:
graph[nick] = set()
#Scan for highlights, then fill the graph
nickre = re.compile("\\b(%s)\\b" % ("|".join(re.escape(nick) for nick in nicks)))
try:
for line in log:
linetype, date, nick, msg = line
#show progress
print "Searching for edges @ %s" % (date)
sys.stdout.flush()
if linetype==MSG:
highlights=set(match.group(1) for match in nickre.finditer(msg))
graph[nick]|=highlights
except KeyboardInterrupt:
pass
#Remove nicks that are not referrenced
activenicks = reduce(set.union,graph.values()) | set(nick for nick in nicks if len(graph[nick])>0)
nicks, unactivenicks = activenicks, nicks
#Generate the graphwiz
print "Generating the graph..."
sys.stdout.flush()
G = pygraphviz.AGraph(strict=False, directed=True)
G.add_nodes_from(nicks)
for nick, highlights in graph.items():
for highlight in highlights:
G.add_edge(nick,highlight)
G.layout(prog=layout)
G.draw(outputimage)
print "Done"
if __name__ == "__main__":
generateGraph(sys.argv[1],sys.argv[2:],"graph.svg")