Skip to content

Instantly share code, notes, and snippets.

@nightuser
Created April 14, 2022 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nightuser/21cfdcd78d03877be3f2b253a683022e to your computer and use it in GitHub Desktop.
Save nightuser/21cfdcd78d03877be3f2b253a683022e to your computer and use it in GitHub Desktop.
Gentoo: list optional dependencies for installed packages
#!/usr/bin/env python3
import re
import portage
import shlex
optfeature_re = re.compile(r'optfeature\s+(.*)$')
packages = portage.db[portage.root]['vartree'].dbapi.cpv_all()
for cpv in packages:
ebuild = portage.db[portage.root]['vartree'].dbapi.findname(cpv)
opts = []
with open(ebuild) as fh:
cont = False
stack = []
for line in fh:
line = line.strip()
if stack:
if stack[-1][-1] == '\\':
stack.append(line)
else:
full = ''.join(l.rstrip('\\') for l in stack)
a = shlex.split(full)
if a[0] != 'inherit':
opts.append(a)
stack = []
else:
m = optfeature_re.search(line)
if m:
stack.append(line)
if opts:
print(cpv)
for opt in opts:
print(' ', opt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment