32 lines
745 B
Python
Executable file
32 lines
745 B
Python
Executable file
#! /usr/bin/env python3
|
|
# encoding: utf-8
|
|
|
|
import glob
|
|
import re
|
|
import sys
|
|
|
|
def grep(exp, filename):
|
|
with open(filename) as f:
|
|
matches = re.findall(exp, f.read())
|
|
|
|
return matches
|
|
|
|
def find_reverse_deps(deps):
|
|
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)
|
|
|
|
return atoms
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) > 1:
|
|
atoms = find_reverse_deps(sys.argv[1:])
|
|
print(" ".join(sorted(atoms)))
|
|
else:
|
|
print("Usage: %s DEPENDENCY [more DEPENDENCIES...]" %(sys.argv[0]))
|
|
print("Finds all reverse deps of DEPENDENCY")
|
|
|
|
sys.exit(1)
|