Created
January 21, 2012 23:30
-
-
Save bak1an/1654513 to your computer and use it in GitHub Desktop.
script to show biggest packages at your rpm-based system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 "-"*40 | |
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