aboutsummaryrefslogtreecommitdiff
blob: 84dd7df3eef26e50ce0700b6237c41da4d569559 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#! /usr/bin/python
#
# $Header$
#
#  Distributed under the terms of the GNU General Public License v2
#  Copyright (c) 2003 Karl Trygve Kalleberg

import portage
import pprint
import sys
import os

__author__ = "Karl Trygve Kalleberg"
__email__ = "karltk@gentoo.org"
__version__ = "0.1.0"
__productname__ = "pkg-size"
__description__ = "Portage package size calculator"

def find(name):
    return portage.portdb.match(name)

def print_size(cpv):
    scpv=portage.catpkgsplit(cpv)
    cat = scpv[0]
    pnv = scpv[1]+"-"+scpv[2]
    if scpv[3] != "r0":
        pnv +="-"+scpv[3]
    db=portage.dblink(cat,pnv,"")
    size=0
    uncounted = 0
    if not os.path.exists(db.getpath()):
        return
    k=db.getcontents()
    if not k:
        return
    for i in k:
        try:
            size += os.stat(i).st_size
        except OSError:
            uncounted += 1
    s = cpv + ": " + str(size) + " bytes (" + str((size+512)/1024) + "KB)"
    if uncounted > 0:
        s += " (" + str(uncounted) + " file(s) not accessible)"
    print s

    
def main():
    # parse parameters
    if len(sys.argv) < 2:
        print "No arguments!"
        return 
    name = sys.argv[1]
    candidates = find(name)
    if len(candidates) == 0:
        print "No candidate packages found!"
        return

    for i in candidates:
            print_size(i)

if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        print "Operation Aborted!"