File: package-sizes

package info (click to toggle)
feta 1.4.15
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 444 kB
  • ctags: 85
  • sloc: perl: 1,200; sh: 192; makefile: 55
file content (105 lines) | stat: -rwxr-xr-x 2,191 bytes parent folder | download | duplicates (3)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/perl -w
# Version: 20011114.1
# Copyright (c) 2001 Kamil Kisiel <kamil@kamilkisiel.net>
# Feta plugin for determining the size of installed packages.
# Licensed under the GNU GPL v2

use strict;

use Getopt::Std;

#
# Some (hopefully) self-explanatory variables. 
#
my %packages; 
my $currentpackage;
my $totalsize;
my $package;
my $packagecount;

#
# Allow for -s and -r command line switches.
#

my %opts;
getopts('qVtysr', \%opts);

#
# Read the dpkg database and create a hash of all installed packages and their sizes.
#
open(DPKG, '/var/lib/dpkg/status');
while ( <DPKG> ){
	if (/^Package\: (.+)\n/){
		$currentpackage = $1;
	}
	#
	# Add packages that are not installed to the "null" key of the hash, this is removed below.
	# 
	if (/^Status\: (.+)\n/){
		unless ($1 eq "install ok installed" || $1 eq "hold ok installed"){
			$currentpackage = 'null';
		}
	}
	if (/^Installed-Size\: (.+)\n/){
		$packages{$currentpackage} = $1;
	}		
}
close(DPKG);
delete $packages{'null'};

#
# Set the page size to the size of the hash plus 4 lines, to accomodate header.
#
$= = (scalar keys %packages) + 4 ;

#
# Print out the list of packages in an order depending on the command line options.
# 
# s - by size
# r - reversed
# 
if ( $opts{'s'} && $opts{'r'} ) {
 	foreach $package (reverse sort { $packages{$a} <=> $packages{$b} } keys %packages){
		output($package);
	}

} elsif ( $opts{'s'} ) {
	foreach $package (sort { $packages{$a} <=> $packages{$b} } keys %packages){
		output($package);
	}

} elsif ( $opts{'r'} ) {
	foreach $package (reverse sort keys %packages){
		output($package);
	}

} else {
	foreach $package (sort keys %packages){
		output($package);
	}
}

#
# Print the total size of all packages at the bottom
#
if (!$opts{'q'}) {
 print "\nTotal size: $totalsize kB\n";
 print "Packages counted: $packagecount\n";
}

sub output {
	my $package = shift;
	write;
	$totalsize += $packages{$package};
	$packagecount++;
}

format STDOUT_TOP =
Package Name							Size
================================================================================
.

format STDOUT =
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<       @>>>>>>>> kB
$package,						$packages{$package}
.