-
Notifications
You must be signed in to change notification settings - Fork 5
/
opkg-show-deps
executable file
·86 lines (72 loc) · 2.16 KB
/
opkg-show-deps
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
#!/usr/bin/env python
import sys, os, posixpath
from glob import glob
import opkg
import getopt
import re
verbose = 0
def usage():
sys.stderr.write("%s [-p Packages] package ...\n" % (sys.argv[0],))
sys.exit(-1)
packages_filename = "Packages"
(opts, remaining_args) = getopt.getopt(sys.argv[1:], "hp:")
for (optkey, optval) in opts:
if optkey == '-h':
usage()
if optkey == '-p':
packages_filename = optval
if ( not remaining_args ):
usage()
packages = opkg.Packages()
packages.read_packages_file(packages_filename)
required = {}
provider_hash = {}
def split_list(str):
r = []
l = str.split(",")
for i in l:
ll = i.split("|")
for ii in ll:
ii = ii.strip()
r.append(ii)
return r
for i in list(packages.packages.keys()):
p = packages.packages[i]
if p.package not in provider_hash:
provider_hash[p.package] = []
provider_hash[p.package].append(p)
if p.provides:
provides = p.provides.split(",")
for prov in provides:
prov = prov.strip()
if prov not in provider_hash:
provider_hash[prov] = []
provider_hash[prov].append(p)
def find_package(name):
if name in provider_hash:
return provider_hash[name]
return None
def recurse(pkg):
required[pkg.package] = 1
if pkg.depends:
deps = split_list(pkg.depends)
for dep in deps:
dep = re.sub("\s*\(.*\)", "", dep)
dep = re.sub("\*$", "", dep)
newpkgs = find_package(dep)
if newpkgs:
for newpkg in newpkgs:
if newpkg.package in required:
return
recurse(newpkgs[0])
else:
sys.stderr.write("unsatisfied dependency of %s on '%s'\n" % (pkg.package, dep))
for root in remaining_args:
pkgs = find_package(root)
if not pkgs:
sys.stderr.write("Can't find root package '%s'\n" % root)
sys.exit(-1)
for p in pkgs:
recurse(p)
for pkg in list(required.keys()):
print(pkg)