eclipse/gen_build_order_graph.py
2019-06-25 21:58:57 +01:00

60 lines
1.8 KiB
Python
Executable file

#!/usr/bin/python3
import yaml
from pygraphviz import AGraph
from subprocess import call
with open("eclipse.yaml", 'r') as stream:
yaml = yaml.safe_load(stream)
rpms = yaml['data']['components']['rpms']
g = AGraph(directed=True, name="G", strict=False, label="Build Order Graph")
ranks = []
for key, value in rpms.items():
rank = value['buildorder']
if rank not in ranks:
ranks.append(rank)
subg = g.get_subgraph(f"{rank}")
if subg is None:
subg = g.add_subgraph(name=f"{rank}", label=f"Build Order {rank}", rank="same")
subg.add_node(f"{rank}")
reqs = []
breqs = []
api = False
for r in value['rationale'].replace('\n', ' ').split('.'):
r = r.strip()
if not r:
continue
if r == 'Module API':
api = True
continue
if r.startswith('Runtime dependency of'):
r = r[len('Runtime dependency of'):]
reqs = [x.strip() for x in r.split(',')]
if r.startswith('Build dependency of'):
r = r[len('Build dependency of'):]
breqs = [x.strip() for x in r.split(',')]
if api:
subg.add_node(key, color='green')
else:
subg.add_node(key)
for req in reqs:
# For Rs, check if also a BR
if req not in breqs:
g.add_edge(key, req, color='blue')
else:
g.add_edge(key, req, color='purple')
for breq in breqs:
# For BRs, check if also a R
if breq not in reqs:
g.add_edge(key, breq, color='red')
ranks.sort()
for idx, rank in enumerate(ranks):
if idx+1 < len(ranks):
g.add_edge(rank, ranks[idx+1], weight=1000)
print(g.string())
g.draw("build_order_graph.png", prog="dot")
call('eog build_order_graph.png &', shell=True)