-
Notifications
You must be signed in to change notification settings - Fork 0
/
aurgraph.py
61 lines (49 loc) · 1.93 KB
/
aurgraph.py
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
#!/usr/bin/env python3
"""
A small cli tool to generate dependency graphs for the aur.
Depends on python requests, networkx and pydot.
To generate a png of the graph you can use the following command:
dot -Tpng graph.dot -ograph.png
"""
from argparse import ArgumentParser
from requests import get
from networkx import DiGraph
from networkx.drawing.nx_pydot import write_dot
AUR_RPC_URL = "https://aur.archlinux.org/rpc/"
class Query:
def __init__(self, parent, relation, args):
self.parent = parent
self.relation = relation
self.args = args
self.args['v'] = 5
self.args['type'] = 'search'
parser = ArgumentParser(description='Generate a graph of the aur packages that depend on ones maintained by a maintainer.')
parser.add_argument('--maintainer', nargs='?', default='cafehaine', help='the maintainer')
args = parser.parse_args()
G = DiGraph()
queries = [
Query(None, None, {'by': 'maintainer', 'arg': args.maintainer})
]
print("==> Fetching informations")
while queries:
query = queries.pop()
print("by {}: {}".format(query.args['by'], query.args['arg']))
r = get(AUR_RPC_URL, params=query.args)
json = r.json()
for package in json['results']:
name = package['Name']
if package['Maintainer'] == args.maintainer:
G.add_node(name, color='red')
else:
G.add_node(name)
if query.parent:
G.add_edge(query.parent, name)
queries.append(Query(name, 'depends', {'by': 'depends', 'arg': name}))
queries.append(Query(name, 'makedepends', {'by': 'makedepends', 'arg': name}))
queries.append(Query(name, 'checkdepends', {'by': 'checkdepends', 'arg': name}))
print("==> Done fetching informations")
print("==> Saving graph as graph.dot")
write_dot(G, 'graph.dot')
print("==> Done saving.")
print("To generate a visual representation of this graph, run the following command:")
print("> dot graph.dot -Tpng -o graph.png")