1. Arne Babenhauserheide
  2. Gentoo-count_pkg_in_overlays


Gentoo-count_pkg_in_overlays / count_pkg_in_overlay.py

#!/usr/bin/env python
### imports ###
from subprocess import call

# First create the list of installed packages
print "# eix -I > /tmp/instl"
call("eix -I > /tmp/instl", shell=True)

# First load the list of installed packages as a list of lines
print "# count packages in overlays"
f = open("/tmp/instl", "r")
instl = f.read().splitlines()
# Cleanup of the temporary file
call("rm /tmp/instl", shell=True)

#: A list of numbers for overlays
overlays = ["[" + str(i) + "]" for i in range(100)]
#: The counts for each overlay. 
counts = {}
#: The corresponding names
names = {}

# Now just count the number of times, the overlay number appers in the data. 
for number in overlays: 
	for line in instl: 
		if number in line: 
			# if we don't yet have an entry for the overlay, 
			# we create one with 0! 
			# reason: every overlay appears again at the end. 
			if not number in counts: 
				counts[number] = 0
				counts[number] += 1

# Now we clean out empty entries from counts. 
for i in counts: 
	if not counts[i]: 
		del counts[i]

# And parse the names
# For this we just grab the first appearance of the number in the 
# reversed list of lines, but only for the actually existing overlays. 
for number in counts: 
	for line in instl: 
		if number in line: 
			names[number] = line

# finally sort the overlays by the number of appearances and print it
# put counts in a list we can sort by the number of appearances. 
overlay_list = []
for number in counts: 
	overlay_list.append((counts[number], number))

# Print the highest count first

# now print the result
for count, number in overlay_list: 
	print count, names[number].split("] ")[1]