forked from adamlaska/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot.py
More file actions
133 lines (100 loc) · 4.5 KB
/
dot.py
File metadata and controls
133 lines (100 loc) · 4.5 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
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
# Copyright The IETF Trust 2017-2020, All Rights Reserved
# -*- coding: utf-8 -*-
# -*- check-flake8 -*-
from django.db.models import Q
from django.template.loader import render_to_string
from ietf.doc.models import RelatedDocument
class Edge(object):
def __init__(self, relateddocument):
self.relateddocument = relateddocument
def __hash__(self):
return hash("|".join([str(hash(nodename(self.relateddocument.source.name))),
str(hash(nodename(self.relateddocument.target.document.name))),
self.relateddocument.relationship.slug]))
def __eq__(self, other):
return self.__hash__() == other.__hash__()
def sourcename(self):
return nodename(self.relateddocument.source.name)
def targetname(self):
return nodename(self.relateddocument.target.document.name)
def styles(self):
# Note that the old style=dotted, color=red styling is never used
if self.relateddocument.is_downref():
return { 'color': 'red', 'arrowhead': 'normalnormal' }
else:
styles = { 'refnorm' : { 'color': 'blue' },
'refinfo' : { 'color': 'green' },
'refold' : { 'color': 'orange' },
'refunk' : { 'style': 'dashed' },
'replaces': { 'color': 'pink', 'style': 'dashed', 'arrowhead': 'diamond' },
}
return styles[self.relateddocument.relationship.slug]
def nodename(name):
return name.replace('-', '_')
def get_node_styles(node, group):
styles = dict()
# Shape and style (note that old diamond shape is never used
styles['style'] = 'filled'
if node.get_state('draft').slug == 'rfc':
styles['shape'] = 'box'
elif not node.get_state('draft-iesg').slug in ['idexists', 'watching', 'dead']:
styles['shape'] = 'parallelogram'
elif node.get_state('draft').slug == 'expired':
styles['shape'] = 'house'
styles['style'] = 'solid'
styles['peripheries'] = 3
elif node.get_state('draft').slug == 'repl':
styles['shape'] = 'ellipse'
styles['style'] = 'solid'
styles['peripheries'] = 3
else:
pass # quieter form of styles['shape'] = 'ellipse'
# Color (note that the old 'Flat out red' is never used
if node.group.acronym == 'none':
styles['color'] = '"#FF800D"' # orangeish
elif node.group == group:
styles['color'] = '"#0AFE47"' # greenish
else:
styles['color'] = '"#9999FF"' # blueish
# Label
label = node.name
if label.startswith('draft-'):
if label.startswith('draft-ietf-'):
label = label[11:]
else:
label = label[6:]
try:
t = label.index('-')
label = r"%s\n%s" % (label[:t], label[t+1:])
except:
pass
if node.group.acronym != 'none' and node.group != group:
label = "(%s) %s" % (node.group.acronym, label)
if node.get_state('draft').slug == 'rfc':
label = "%s\\n(%s)" % (label, node.canonical_name())
styles['label'] = '"%s"' % label
return styles
def make_dot(group):
references = Q(source__group=group, source__type='draft', relationship__slug__startswith='ref')
both_rfcs = Q(source__states__slug='rfc', target__docs__states__slug='rfc')
inactive = Q(source__states__slug__in=['expired', 'repl'])
attractor = Q(target__name__in=['rfc5000', 'rfc5741'])
removed = Q(source__states__slug__in=['auth-rm', 'ietf-rm'])
relations = ( RelatedDocument.objects.filter(references).exclude(both_rfcs)
.exclude(inactive).exclude(attractor).exclude(removed) )
edges = set()
for x in relations:
target_state = x.target.document.get_state_slug('draft')
if target_state != 'rfc' or x.is_downref():
edges.add(Edge(x))
replacements = RelatedDocument.objects.filter(relationship__slug='replaces',
target__docs__in=[x.relateddocument.target.document for x in edges])
for x in replacements:
edges.add(Edge(x))
nodes = set([x.relateddocument.source for x in edges]).union([x.relateddocument.target.document for x in edges])
for node in nodes:
node.nodename = nodename(node.name)
node.styles = get_node_styles(node, group)
return render_to_string('group/dot.txt',
dict( nodes=nodes, edges=edges )
)