Thursday, September 25, 2008

Manaully clean your Gentoo world file

I've been in a love-hate relationship with Gentoo for over 3 years now. Luckily there's a lot more love than hate these days. Well 3 years is a long time and it's time to clean this bad boy up...

There's a lot of articles on-line on how to remove cruft and deprecated packages etc. But I struggled to find one that will help you clean up your world file. Being a bit of a quick fix kind of guy, I hammered this little python script together, which will loop through your world file and find the package description for each entry. The script isn't perfect, but it gets the job done for the most part. I still have to manually edit the world file, but at least now I get a description of each entry as I step through the file.

Here's what you need to do:

Log in as root and fire up a text editor:

And paste the following:
import os
import string
import sys

if __name__ == '__main__':
f_in = open("/var/lib/portage/world")

lines = f_in.readlines()

for line in lines:
index = line.find("/")
length = len(line) - 1

if(index > 0):
print ""
print "--------------------------------------"
print line[index+1:length]
print ""
cmd = "emerge -s " + line[index+1:length] + " | grep -A7 '" + line[:length] + "' "


Exit and save (Ctrl+x, Enter). Run the script:
Just hit enter after each lookup and manually remove the entry from your world file. Since the script uses grep to filter the ermerge -s results you might get multiple descriptions for some packages. Like dev-java/java-config will list dev-java/java-config-wrapper too. A slight nuisance, but who cares?

Note: It is not considered safe to update your world file manually, so don't mess around if you don't know what you're doing. Please make a backup before editing.

1 comment:

Max said...

Hi all,

it's better/much faster to use the program eix to see the information of the programs in world. First run once:

# emerge -av app-portage/eix
# eix-sync
[for emerge --sync and eix-update]

Now the eix cache and portage is up-to-date and you could use the search options of eix, e.g.

$ eix --world -c
[all packages in world shown in condensed mode and colour]
$ eix dev-lang/python
[shows all information about the specified package]

For further information about the eix read the man-page, please.

Kind regards,
der Max