#!python3 # # Copyright (C) 2019 Adrien Destugues # # Distributed under terms of the MIT license. from os import listdir from os.path import isfile, join import subprocess import re path = "/system/packages" packages = [join(path, f) for f in listdir(path) if(isfile(join(path, f)))] print('strict digraph {\nnode [ fontname="Noto", fontsize=10];') pmap = {} rmap = {} for p in packages: pkgtool = subprocess.Popen(['package', 'list', '-i', p], stdout = subprocess.PIPE) infos, stderr = pkgtool.communicate() provides = [] requires = [] for line in infos.split(b'\n'): if line.startswith(b"\tprovides:"): provides.append(line.split(b' ')[1]) if line.startswith(b"\trequires:"): line = line.split(b' ')[1] if b'>' in line: line = line.split(b'>')[0] if b'=' in line: line = line.split(b'=')[0] if line != b'haiku' and line != b'haiku_x86': requires.append(line) for pro in provides: pmap[pro] = provides[0] if len(requires) > 0: rmap[provides[0]] = requires for k,v in rmap.items(): for dep in v: if dep in pmap: dep = pmap[dep] print('"%s" -> "%s"' % (k.decode('utf-8'), dep.decode('utf-8'))) print("}")