Created
July 6, 2016 08:25
-
-
Save geekman/f97c70db5a86c8d726910022c32453f1 to your computer and use it in GitHub Desktop.
shows unsatisfied dependencies for a set of ipkg files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# | |
# show unsatisfied depedencies for a set of ipkg files | |
# useful when creating a self-sufficient set of packages offline | |
# | |
# 2016.07.05 darell tan | |
# | |
import tarfile | |
import sys | |
import os | |
def get_control_dict(ipkg): | |
pkgf = tarfile.open(ipkg, 'r') | |
cf = tarfile.open(fileobj=pkgf.extractfile('./control.tar.gz'), mode='r') | |
control = cf.extractfile('./control').readlines() | |
cf.close() | |
pkgf.close() | |
# parse control data | |
control_dict = {} | |
for l in control: | |
kv = l.strip().split(':', 1) | |
k = kv[0].strip() | |
control_dict[k] = kv[1].strip() if len(kv) > 1 else None | |
return control_dict | |
def main(): | |
# collect deps | |
dep_map = {} | |
pkgdir = sys.argv[1] | |
filelist = [pkgdir] if os.path.isfile(pkgdir) else \ | |
[os.path.join(pkgdir, f) for f in os.listdir(pkgdir)] | |
for f in filelist: | |
if not f.endswith('.ipk'): | |
continue | |
print 'processing ' + f | |
c = get_control_dict(f) | |
deps = c.get('Depends', None) | |
dep_map[c['Package']] = [] if not deps else \ | |
[d.strip() for d in deps.split(',')] | |
# parse deps | |
allpkgs = set(dep_map.keys()) | |
for pkg in dep_map: | |
pkg_deps = dep_map[pkg] | |
print pkg, pkg_deps | |
missing_deps = set(pkg_deps) - allpkgs | |
dep_map[pkg] = missing_deps | |
print '' | |
allmissing = set() | |
for pkg in dep_map: | |
allmissing |= dep_map[pkg] | |
print 'unsatisfied deps:' | |
print allmissing | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment