Skip to content

Instantly share code, notes, and snippets.

@Tatsh
Last active July 13, 2020 18:20
Show Gist options
  • Select an option

  • Save Tatsh/032f55fb8047881746eb to your computer and use it in GitHub Desktop.

Select an option

Save Tatsh/032f55fb8047881746eb to your computer and use it in GitHub Desktop.
Exceptional USE flags
#!/usr/bin/env python
import re
import sys
from sh import eix
if __name__ == '__main__':
atoms = eix(('-I', '--nocolor', '--only-names')).strip().splitlines()
with open('/etc/portage/make.conf') as fp:
use_flags = []
for line in fp.read().splitlines():
if not line.startswith('USE='):
continue
use_flags = sorted(x.strip('"') for x in line.split('=')[1].split(' '))
break
for atom in atoms:
for line in eix(('-I', '--nocolor', atom)).stdout.readlines():
if 'Installed versions' not in line:
continue
flags = None
for i in reversed(range(2, 5)):
try:
flags = line.strip().split('(')[i].rstrip(')').split(' ')
flags = [x for x in flags if not re.search(r'[A-Z]', x)]
flags = [x for x in flags if not re.match(r'^[0-9]+[\:/]', x)]
except IndexError:
continue
if not flags:
print('Assuming no USE flags for %s' % (atom,), file=sys.stderr)
break
flags = [x for x in flags if x not in use_flags]
if not flags:
print('No exclusive USE flags for %s' % (atom,), file=sys.stderr)
break
print('%s -> %s' % (atom, flags,))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment