#!/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}")
subg.add_node(key)
rs = value['rationale'].replace('\n', ' ').split('.')
reqs = []
breqs = []
for r in rs:
r = r.strip()
if not r or r == 'Module API':
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(',')]
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)