added cave-rdep and cave-stat
This commit is contained in:
parent
a7b844d450
commit
763313adad
3 changed files with 55 additions and 0 deletions
32
bin/cave-rdep
Executable file
32
bin/cave-rdep
Executable file
|
@ -0,0 +1,32 @@
|
|||
#! /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)
|
20
bin/cave-stat
Executable file
20
bin/cave-stat
Executable file
|
@ -0,0 +1,20 @@
|
|||
#! /usr/bin/env python3
|
||||
# encoding: utf-8
|
||||
|
||||
import psutil
|
||||
|
||||
def cave_stat():
|
||||
for proc in psutil.process_iter():
|
||||
if proc.name() == "cave":
|
||||
cmdline = proc.cmdline()
|
||||
|
||||
if "--x-of-y" in cmdline:
|
||||
position = cmdline[-1]
|
||||
dest_idx = cmdline.index("--destination")
|
||||
atom = cmdline[dest_idx - 1]
|
||||
|
||||
yield "Installing %s (%s)" %(atom, position)
|
||||
|
||||
if __name__ == "__main__":
|
||||
for state in cave_stat():
|
||||
print(state)
|
Loading…
Add table
Add a link
Reference in a new issue