Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

One can select testing packages on a gentoo stable system by adding a line with the following syntax to keywords list:

cat /etc/portage/package.keywords

=dev-python/ipython-0.13.2 ~amd64
# and many lines later
=dev-python/ipython-0.14.1 ~amd64
# and many lines later
>=dev-python/ipython-0.13.4 ~amd64

This file will grow within the time and sooner or later one can not remember which lines are obsolete.

How can I tidy up the list with a script from time to time?

A line should be deleted,

  • if the testing version is already stabilized
  • >= was used for the same package
  • = was used for the same package with smaller version number
share|improve this question

2 Answers 2

I wrote a small python script that takes care of this problem. The logic looks at each line in the file package.accept_keywords and only acts on lines that start with = or <=. These lines have a maximum bound version so we can check if they are needed anymore. Lines without a qualifier or a >= are left as-is as we cannot know if they are obsolete.

The lines that we care about are then parsed and the installed version of the package is checked. If the installed version is newer than the keyworded version, or is not longer installed at all, the keyword is considered obsolete. If the installed package is the same version as the keyworded version then the installed package is checked to see if it is still keyworded. If it has been stabilized, the line is obsoleted, otherwise it is retained.

#!/bin/env python

import re
import portage

vartree = portage.db[portage.root]['vartree']

with open('/etc/portage/package.accept_keywords') as f:
    for x in f:
        # eat newline
        x = x.rstrip()
        # we only want lines with a bounded max version
        if re.match('^(=|<=)',x):
            # get the package cpv atom -- strip the =|<= and the trailing keyword(s)
            cpv_masked = re.sub('[<=]','',x.split(' ',1)[0])
            cat, pkg, ver, rev = portage.catpkgsplit(cpv_masked)
            # get cpv for all installed versions of the package
            cpv_installed = vartree.dep_match(cat+'/'+pkg)
            for cpv in cpv_installed:
                cmp = portage.pkgcmp(portage.pkgsplit(cpv), portage.pkgsplit(cpv_masked))
                # if the installed version is not newer than the masked version
                if (cmp <= 0):
                    # check if this version is still keyworded
                    cpv_keywords = vartree.dbapi.aux_get(cpv, ['KEYWORDS'])
                    # keep keyword if the package has no keywords (**)
                    if not cpv_keywords[0]:
                    # check if the installed package is still keyworded
                    for cpv_keyword in cpv_keywords[0].split(' '):
                        if cpv_masked_keyword == cpv_keyword:
                            # it is, keep the atom and move on to the next one
            # keep atoms that have an unbounded max version

This will print the new keywords file to standard out. Note: do not redirect the output back into /etc/portage/package.accept_keywords or you will clobber the file and lose everything.

This will go a long way toward cleaning up your keywords file and for your other concerns, sorting the file and then examining it for multiple lines for the same package will help resolve most of what is left.

share|improve this answer

Start with eix -tT. Install app-portage/eix to get that.

share|improve this answer
I do not understand how eix -tT solves this. Can you explain it a bit more please? –  Jonas Stein Jul 13 at 20:35
I think you'd have to pastebin some output and point to line numbers of parts you don't understand. –  lkraav Jul 13 at 20:49
I wish there was more info. This leads to "tips and tricks" and the link to the original blog post is dead. This helps a bit. The package has been active recently. The homepage link points to eix.berlios.de but this doesn't exist. Where are the manpages for that online(with all the options)? –  Amphiteóth Jul 22 at 20:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.