blob: 98e023d162c39cdfc2892443d9d5497224564090 (
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
67
68
69
70
71
72
73
74
|
#!/usr/bin/python
import os, sys, output
spinpos = 0
spinner = "/-\\|/-\\|/-\\|/-\\|\\-/|\\-/|\\-/|\\-/|"
def update_spinner():
global spinner, spinpos
spinpos = (spinpos+1) % len(spinner)
sys.stdout.write("\b\b "+spinner[spinpos])
sys.stdout.flush()
def formatSize(x):
x = int(x)
if x < 1024:
return str(x) + ' B'
if x < 1024 * 1024:
return '%.2f KB' % (float(x) / 1024)
return '%.2f MB' % (float(x) / (1024.0 * 1024.0))
packages = {}
total_size = 0
print output.blue('Counting... ')
counter = 0
for category in sorted(os.listdir('/var/db/pkg/')):
print output.green(' *'),category,' ',
update_spinner()
for package in sorted(os.listdir('/var/db/pkg/' + category)):
fh = file('/var/db/pkg/' + category + '/' + package + '/CONTENTS')
content = fh.readlines()
fh.close()
size = 0
for entity in content:
counter += 1
if counter % 10 == 0:
update_spinner()
data = entity.strip().split(' ')
if data[0] != 'obj':
continue
try:
size += os.path.getsize(data[1])
except:
if '--report-missing' in sys.argv:
print '\n', output.red(' *'), 'File missing:', data[1],
pass
total_size += size
packages[category + '/' + package] = size
print '\b '
print
if '--sort-size' in sys.argv:
pkgs = packages.items()
pkgs2 = []
for pkg in pkgs:
pkgs2 += [[ pkg[1], pkg[0] ]]
pkgs = pkgs2
del(pkgs2)
for package in sorted(pkgs):
print output.green(' * ') + output.bold(package[1]) + ' - ' + formatSize(package[0])
else:
for package in sorted(packages.keys()):
print output.green(' * ') + output.bold(package) + ' - ' + formatSize(packages[package])
print output.green('Total size:'), formatSize(total_size)
|