Skip to content

Instantly share code, notes, and snippets.

@bak1an
Created January 21, 2012 23:30
Show Gist options
  • Save bak1an/1654513 to your computer and use it in GitHub Desktop.
Save bak1an/1654513 to your computer and use it in GitHub Desktop.
script to show biggest packages at your rpm-based system
#!/usr/bin/python
# script to show biggest packages at your rpm-based system
# just run it like 'python biggest_packages.py | less'
import subprocess
packages = {}
process = subprocess.Popen(r"rpm -qa --queryformat '%{size}|%{name}-%{version}-%{release}\n'",
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
for line in process.stdout:
data = line.split('|')
packages[long(data[0])] = data[1]
process.wait()
sorted_sizes = sorted(packages, reverse=True)
si = ["", "K", "M"]
def get_h(s):
h = s
for i in range(1, len(si)):
if (s / pow(1024, i)) == 0:
break
else:
h = "%s%s" % ((s / pow(1024, i)), si[i])
return h
print "Total packages installed: %s" % len(sorted_sizes)
print "And they are using %s of disk space" % get_h(reduce(lambda a,b: a+b, sorted_sizes, 0L))
print
print "-"*40
print
for s in sorted_sizes:
print get_h(s),packages[s],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment