Created
April 14, 2022 16:37
-
-
Save nightuser/21cfdcd78d03877be3f2b253a683022e to your computer and use it in GitHub Desktop.
Gentoo: list optional dependencies for installed packages
This file contains hidden or 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 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