Skip to content

Instantly share code, notes, and snippets.

@geekman
Created July 6, 2016 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geekman/f97c70db5a86c8d726910022c32453f1 to your computer and use it in GitHub Desktop.
Save geekman/f97c70db5a86c8d726910022c32453f1 to your computer and use it in GitHub Desktop.
shows unsatisfied dependencies for a set of ipkg files
#!/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