3
# wanna-build-statistics: print statistics for wanna-build databases
4
# Copyright © 1998 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
# General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program. If not, see
18
# <http://www.gnu.org/licenses/>.
20
#######################################################################
24
use vars qw($verbose $dist $database);
31
$database = "build-db";
33
# TODO: Use Getopt::Long.
34
while( @ARGV && $ARGV[0] =~ /^-/ ) {
36
if (/^-v$/ || /^--verbose$/) {
39
elsif (/^-d/ || /^--dist/) {
40
if (/^-d(.)/ || /^--dist=(.)/) {
44
die "$_ option missing argument\n";
49
# TODO: Use distribution list from main configuration
50
$dist = "oldstable" if $dist eq "o";
51
$dist = "stable" if $dist eq "s";
52
$dist = "testing" if $dist eq "t";
53
$dist = "unstable" if $dist eq "u";
54
die "Bad distribution\n" if !isin($dist, qw(stable testing unstable stable-security testing-security oldstable oldstable-security));
59
elsif (/^--database=(.*)$/) {
63
die "Unknown option: $_\n";
67
my($lastmsg, %n_state, $total, %n_builder);
68
open( PIPE, "wanna-build --database=$database --dist=$dist --list=all 2>&1 |" )
69
or die "Cannot spawn wanna-build: $!\n";
71
if (/^Database for $dist doesn't exist$/) {
74
elsif (/^Total (\d+) package\(s\) in state (\S+)\.$/) {
77
elsif (/^Total (\d+) package\(s\)$/) {
80
elsif (/^\S+: (\S+) by (\S+)/) {
81
$n_builder{$1}->{$2}++;
88
die "Bad exit status $? from wanna-build\n";
91
print "Distribution $dist:\n";
92
print "--------------", "-" x length($dist), "\n";
96
my @state_list = qw(Installed Needs-Build Building Built
97
Build-Attempted Uploaded Failed Dep-Wait
98
Failed-Removed Dep-Wait-Removed Not-For-Us);
101
grep { $statewidth = length($_) if length($_) > $statewidth } @state_list;
102
my $startcol = $statewidth + 9;
104
my($state, $builder);
105
foreach $state (@state_list) {
106
printf "%-${statewidth}s: %5d", $state, $n_state{$state};
107
if (!keys %{$n_builder{$state}}) {
112
foreach $builder (keys %{$n_builder{$state}}) {
113
$sum += $n_builder{$state}->{$builder};
115
$n_builder{$state}->{"unknown"} = $n_state{$state} - $sum;
119
foreach $builder (sort keys %{$n_builder{$state}}) {
120
next if !$n_builder{$state}->{$builder};
121
my $str = "$builder: $n_builder{$state}->{$builder}";
122
$str = ", $str" if !$is_first;
124
if ($pos + length($str) > $total_width) {
125
print ",\n", " " x $startcol;
130
$pos += length($str);
134
printf "%-${statewidth}s: %5d\n", "total", $total;
137
$total -= $n_state{"Not-For-Us"};
138
print percent(qw(Installed)), " up-to-date, ";
139
print percent(qw(Installed Uploaded)), " if also counting uploaded pkgs\n";
140
print percent(qw(Built Installed Uploaded)), " if also counting built pkgs\n";
141
print percent(qw(Needs-Build)), " uncompiled\n";
142
print percent(qw(Building)), " currently building (short-term delay)\n";
143
print percent(qw(Build-Attempted)), " currently failed building (short-term delay)\n";
144
print percent(qw(Failed Dep-Wait)), " failed or waiting (long-term delay)\n";
154
return sprintf "%6.2f%%", $n*100/$total if $total;
155
return sprintf "%6.2f%%", 0;
160
return grep( $_ eq $val, @_ );