You are not logged in.

#1 2008-07-06 10:56:49

ddaedalus
Member
Registered: 2008-01-14
Posts: 54

Small python script to get packagesizes of installed packages

Hi,

having only allocated 10GB to my / partition, i needed to lose some big but unused packages. I wrote a small python script which accumulates sizes of installed packages.

It also finds packages missing files. But somehow reinstalling these package does not help.

Beware: This was an 30min hack-job. If this script eats your hard-drives and kidnapps your children, you are on your own.

License: GPL3
Usage: python PacmanPkgSize.py | sort -g

import subprocess
import re
import os

lineExp = re.compile('(.*)$')
sepExp = re.compile(' ')
o = subprocess.Popen('pacman -Ql', shell=True, stdout=subprocess.PIPE).stdout

pkgs = {}

for line in o:
        fields = sepExp.split(lineExp.match(line).group(1))
        try:
                pkgs[fields[0]] = pkgs.get(fields[0], 0) + os.lstat(fields[1]).st_size
        except OSError:
                print "Possibly broken package %s. Cannot lstat %s." % (fields[0], fields[1])

for pkg in pkgs:
        print pkgs[pkg], pkg

Output:

Possibly broken package ttf-cheapskate. Cannot lstat /usr/share/fonts/TTF/It.
Possibly broken package ttf-ms-fonts. Cannot lstat /tmp/ttf-ms-fonts/.
Possibly broken package ttf-ms-fonts. Cannot lstat /tmp/ttf-ms-fonts/andale32.exe.
Possibly broken package ttf-ms-fonts. Cannot lstat /tmp/ttf-ms-fonts/arial32.exe.
...
[ cropped for brevity ]
...
23640039 vi
23822267 xorg-server
24578451 smbclient
24730729 gtk2
24906412 openoffice-spell-en
24966338 nvidia-utils
27049739 pidgin
27148628 qt3
28588825 kdegraphics
28737773 glibc
29195438 kdemultimedia
30315310 amarok-base
33795308 kdenetwork
33834216 qemu
40207056 perl
42617503 gimp
42767840 kdevelop
44759277 kdebindings
45234202 qt
48155031 ghostscript
48352825 python
54859162 xulrunner
57781794 kdepim
58162454 kdelibs
59972413 kdeedu
64560818 kdebase
64810725 inkscape
64865571 gcc
70541458 wine
73799608 kernel26
108425886 jre
275442674 openoffice-base
323698098 ghc

Last edited by ddaedalus (2008-07-06 11:28:34)

Offline

#2 2008-07-06 12:23:55

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,896
Website

Re: Small python script to get packagesizes of installed packages

nice script only size of package output could be much easier if it was in mb's a simple calculation [divide by 1024?]

thanks

MrG


Mr Green

Offline

#3 2008-07-06 13:47:37

moljac024
Member
From: Serbia
Registered: 2008-01-29
Posts: 2,676

Re: Small python script to get packagesizes of installed packages

And maybe an option to sort from biggest to smallest or vice versa. Nice script though wink


The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...

Offline

#4 2008-07-07 18:20:16

ddaedalus
Member
Registered: 2008-01-14
Posts: 54

Re: Small python script to get packagesizes of installed packages

Thanks for the nice replies.

@Mr Green: Display is in bytes because of 1. KISS, 2. If you wanted to postprocess the output, you would have to convert it back.
@moljac024: Unix philosophy. There is sort for sorting wink Just pipe through sort -g

Last edited by ddaedalus (2008-07-07 18:20:38)

Offline

#5 2008-07-07 19:15:41

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,896
Website

Re: Small python script to get packagesizes of installed packages

thats ok merely a suggestion nothing more, does the job thats the main thing.....


Mr Green

Offline

#6 2008-07-07 19:45:12

moljac024
Member
From: Serbia
Registered: 2008-01-29
Posts: 2,676

Re: Small python script to get packagesizes of installed packages

ddaedalus wrote:

Thanks for the nice replies.

@Mr Green: Display is in bytes because of 1. KISS, 2. If you wanted to postprocess the output, you would have to convert it back.
@moljac024: Unix philosophy. There is sort for sorting wink Just pipe through sort -g

Nice. A great KISSer you are sir! wink

lol

Last edited by moljac024 (2008-07-07 19:45:35)


The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...

Offline

Board footer

Powered by FluxBB