Created
May 13, 2015 21:36
-
-
Save vvavrychuk/4f357a30a4f50cba0616 to your computer and use it in GitHub Desktop.
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/env python | |
"""Can check if one packed depends on another and can simplify packets | |
list by removing dependencies""" | |
import apt | |
import sys | |
cache = apt.Cache() | |
def all_or_dependencies(dependencies): | |
all_dependencies = [] | |
for dep in dependencies: | |
all_dependencies.extend(dep.or_dependencies) | |
return all_dependencies | |
def all_dependencies_recursive(pkg, dependencies): | |
pkg_dependencies = all_or_dependencies(pkg.candidate.dependencies) | |
for dep in pkg_dependencies: | |
if dep.name in dependencies: | |
continue | |
dependencies.append(dep.name) | |
if dep.name in cache: | |
all_dependencies_recursive(cache[dep.name], dependencies) | |
def all_dependencies(pkg): | |
dependencies = [] | |
all_dependencies_recursive(pkg, dependencies) | |
return dependencies | |
def check(pkg, dep): | |
for pkg_dep in all_dependencies(cache[pkg]): | |
if pkg_dep == dep: | |
return True | |
return False | |
def simplify(pkgs): | |
result = pkgs[:] | |
for pkg1 in pkgs: | |
for pkg2 in pkgs: | |
if pkg1 == pkg2: | |
continue | |
if pkg2 not in result: | |
continue | |
if check(pkg1, pkg2): | |
result.remove(pkg2) | |
return result | |
if sys.argv[1] == "check": | |
print check(sys.argv[2], sys.argv[3]) | |
elif sys.argv[1] == "simplify": | |
print " ".join(simplify(sys.argv[2:])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment