Commits

Arne Babenhauserheide  committed 6deb70f

Count packages installed from each overlay.

  • Participants

Comments (0)

Files changed (1)

File count_pkg_in_ovrly.py

+#!/usr/bin/env python
+# First load the list of installed packages as a list of lines
+f = open("installierte-pakete-2009-01-29.txt", "r")
+instl = f.read().splitlines()
+f.close()
+
+#: 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
+			else: 
+				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. 
+instl.reverse()
+for number in counts: 
+	for line in instl: 
+		if number in line: 
+			names[number] = line
+			break
+
+# 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))
+
+overlay_list.sort()
+# Print the highest count first
+overlay_list.reverse()
+
+# now print the result
+for count, number in overlay_list: 
+	print count, names[number]