Created
July 5, 2017 19:15
-
-
Save korc/920f0102dc576d20413e4d3e7de48aec to your computer and use it in GitHub Desktop.
Shows dependencies of installed debian packages, recursively if asked
This file contains hidden or 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 | |
| import apt | |
| import sys | |
| import os | |
| def print_deb_deps(name, recurse=1, prep="", _processed=None): | |
| if _processed is None: _processed={} | |
| print "%s%s:"%(prep, name), | |
| sys.stdout.flush() | |
| try: inst=cache[name].installed | |
| except KeyError: | |
| print "(not found in archive)" | |
| return | |
| if inst is None: | |
| print "not installed" | |
| return | |
| print inst.version | |
| if name in _processed: | |
| print "%s (deps already shown)"%(prep,) | |
| return | |
| _processed[name]=inst | |
| if recurse: | |
| for dep_group in inst.dependencies: | |
| for idx,dep in enumerate(dep_group): | |
| if idx: | |
| print prep+" OR" | |
| print_deb_deps(dep.name, recurse - 1, prep + " ", _processed) | |
| if __name__=='__main__': | |
| if len(sys.argv)<2: | |
| print >>sys.stderr, "Usage: %s <pkgname> [<recurse=1>]"%(os.path.basename(sys.argv[0]),) | |
| raise SystemExit(1) | |
| cache=apt.Cache() | |
| print_deb_deps(sys.argv[1], 1 if len(sys.argv) < 3 else int(sys.argv[2])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment