added a half-assed version-less mode to cave-rdep
This commit is contained in:
parent
51d1cd1926
commit
58a13407d6
1 changed files with 43 additions and 4 deletions
|
@ -5,25 +5,64 @@ import glob
|
|||
import re
|
||||
import sys
|
||||
|
||||
def is_a_version(token):
|
||||
"""
|
||||
Returns True iff token is a portage version spec (i.e. contains only numbers or ".").
|
||||
"""
|
||||
|
||||
for A in token:
|
||||
a = ord(A)
|
||||
if not (0x30 <= a <= 0x39 or a == 0x2e):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def strip_version(atom):
|
||||
"""
|
||||
Removes the =version-123 spec from a portage atom.
|
||||
|
||||
Works like 99% of the time. Good enough for the girls I go out with.
|
||||
"""
|
||||
|
||||
parts = atom[1:].split("-")
|
||||
wanted = []
|
||||
|
||||
for part in parts:
|
||||
if is_a_version(part):
|
||||
break
|
||||
|
||||
wanted.append(part)
|
||||
|
||||
return "-".join(wanted)
|
||||
|
||||
def grep(exp, filename):
|
||||
with open(filename) as f:
|
||||
matches = re.findall(exp, f.read())
|
||||
|
||||
return matches
|
||||
|
||||
def find_reverse_deps(deps):
|
||||
def find_reverse_deps(deps, version=True):
|
||||
all_dep_files = glob.glob("/var/db/pkg/*/*/*DEPEND")
|
||||
|
||||
regexp = "(%s)[^:]*:[^/]+/[^=]+=" %("|".join(deps))
|
||||
matching_files = set(f for f in all_dep_files if grep(regexp, f))
|
||||
atoms = set("=" + f[12:].rsplit("/", 1)[0] for f in matching_files)
|
||||
atoms = {"=" + f[12:].rsplit("/", 1)[0] for f in matching_files}
|
||||
|
||||
if not version:
|
||||
atoms = {strip_version(a) for a in atoms}
|
||||
|
||||
return atoms
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) > 1:
|
||||
atoms = find_reverse_deps(sys.argv[1:])
|
||||
if sys.argv[1] == "-v":
|
||||
version = False
|
||||
targets = sys.argv[2:]
|
||||
else:
|
||||
version = True
|
||||
targets = sys.argv[1:]
|
||||
|
||||
atoms = find_reverse_deps(targets, version)
|
||||
print(" ".join(sorted(atoms)))
|
||||
else:
|
||||
print("Usage: %s DEPENDENCY [more DEPENDENCIES...]" %(sys.argv[0]))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue