You are not logged in.

#1 2008-06-13 09:56:12

abhidg
Member
From: City of Kol
Registered: 2006-07-01
Posts: 184
Website

instsize - which packages are taking up the most space?

#!/usr/bin/env python                                                                             
# Prints out packages installed on system                                                         
# ordered in descending order on size.                                                            

# Abhishek Dasgupta                                                                               

import subprocess as S
import pickle, os

storage = '/home/username/.config/instsize'
def appendpkg(s): pkgsizes[s] = size(s)
def sgn(x):
    if x == 0:
        return 0
    else:
        return int(x/abs(x))

execo = lambda s: S.Popen(s.split(' '), stdout=S.PIPE).communicate()[0]
size = lambda s: float(filter(lambda s: s[:9] == 'Installed', execo('pacman -Qi '+s).split("\n"))\
[0][17:-2])

packages = execo('pacman -Qq').split("\n")[:-1]

def printpkg(p):
    print "%-30s %.2f" % (p, pkgsizes[p])

if os.path.exists(storage):
    p1 = open(storage, 'rb')
    pkgsizes = pickle.load(p1)
    p1.close()
else:
    pkgsizes = {}
    map(appendpkg, packages)
    p1 = open(storage, 'wb')
    pickle.dump(pkgsizes, p1)

packages.sort(cmp=lambda x,y: sgn(pkgsizes[x] - pkgsizes[y]), reverse=True)
map(printpkg, packages)

The script saves the installsizes to $HOME/.config/instsize so that later access is faster.
To force regeneration of the cache, just remove the $HOME/.config/instsize file.

Offline

#2 2008-06-13 20:23:40

robmaloy
Member
From: Germany
Registered: 2008-05-14
Posts: 263

Re: instsize - which packages are taking up the most space?

nice little script

suggestion

you could determine username automatically:

username = os.getenv('USER')

storage = '/home/' + username + '/.config/instsize'

☃ Snowman ☃

Offline

#3 2008-06-13 21:20:18

Sp4rkR4t
Member
From: Southampton
Registered: 2008-05-06
Posts: 110

Re: instsize - which packages are taking up the most space?

Nice script.

Offline

#4 2008-06-14 05:43:49

sabooky
Member
Registered: 2006-11-02
Posts: 89

Re: instsize - which packages are taking up the most space?

Just curious how is this script different than this?

Offline

Board footer

Powered by FluxBB