~lamont/launchpad-buildd/wanna-build

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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/perl
#
# check-old-build: check for packages which are in Building for extended time
# Copyright (C) 1998 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# $Id: check-old-builds,v 1.10 2000/09/11 11:40:02 rnhodek Exp $
#
# $Log: check-old-builds,v $
# Revision 1.10  2000/09/11 11:40:02  rnhodek
# Added a host part when sending mails.
#
# Revision 1.9  1999/08/03 11:07:59  rnhodek
# Ignore "Database locked" lines from wanna-build.
#
# Revision 1.8  1999/07/09 13:19:00  rnhodek
# In old-build mails, add a note what happens without uploaded-build.
#
# Revision 1.7  1999/06/02 12:39:59  rnhodek
# Add /usr/local/bin to $PATH if not there yet.
#
# Revision 1.6  1999/05/31 11:33:55  rnhodek
# Remove calls to symlinks of wanna-build (list-needs-build, build-info etc.)
# and use wanna-build itself with appropriate option instead (this removes the
# necessity to have the symlinks; you may still want them for typing
# convenience...)
# Remove assumption that wanna-build & Co. are installed in /usr/local; remove
# absolute paths where possible and otherwise search for it in /usr/local/bin
# and /usr/bin.
# do-merge-*: Remove hardcoded /usr/local/var/debbuild path; extract the path
# from /etc/wanna-build-conf.
#
# Revision 1.5  1999/03/09 12:05:59  rnhodek
# Handle "Database for DIST doesn't exist" output.
#
# Revision 1.4  1999/02/03 11:20:51  rnhodek
# Remove packages from reported-old-builds that aren't in state Building
# anymore.
#
# Revision 1.3  1999/01/19 13:00:02  rnhodek
# Check in all distributions, not only in unstable.
#
# Revision 1.2  1998/11/06 13:50:40  rnhodek
# Remove debugging stuff.
#
# Revision 1.1  1998/11/06 13:48:56  rnhodek
# Initial writing
#

use strict;
use Time::Local;

my $HOME = $ENV{'HOME'}
	or die "HOME not defined in environment!\n";

$ENV{PATH} .= ":/usr/local/bin" if $ENV{'PATH'} !~ m,/usr/local/bin(:|$),;

my $reported_file = "$HOME/lib/reported-old-builds";
my $list_cmd = "wanna-build --list=building -v";
my $report_days = 10;
my $mailprog = "/usr/lib/sendmail";
chomp( my $mailname = `cat /etc/mailname` || `hostname` );
my $sender = $ENV{'LOGNAME'} || (getpwuid($<))[0];

my ($pkg, $builder, $date);
my %reported;
my %seen;
my $now = time;
my $report_time = $report_days * 24*60*60;

my %monname = ('jan', 0,
			   'feb', 1,
			   'mar', 2,
			   'apr', 3,
			   'may', 4,
			   'jun', 5,
			   'jul', 6,
			   'aug', 7,
			   'sep', 8,
			   'oct', 9,
			   'nov', 10,
			   'dec', 11 );

if (open( F, "<$reported_file" )) {
	while( <F> ) {
		next if !/^(\S+)\s+(\S+)\s+(\d+)$/;
		$reported{$2}->{$1} = $3;
	}
	close( F );
}

my $dist;
foreach $dist (qw(stable frozen unstable)) {
	open( PIPE, "$list_cmd --dist=$dist 2>&1 |" )
		or die "Cannot spawn $list_cmd: $!\n";
	while( <PIPE> ) {
		next if /^wanna-build Revision/ || /^Total \d+ package/;
		if (/^Database for \S+ doesn't exist/i) {
			last;
		}
		elsif (m,^\S*/(\S+) by (\S+) \[.*\]$,) {
			($pkg, $builder) = ($1, $2);
			$seen{$dist}->{$pkg} = 1;
		}
		elsif (/^\s+Previous state was \S+ until (.*)$/) {
			$date = parse_date($1);
			check( $dist, $pkg, $builder, $date );
		}
		elsif (/^Database locked by \S+ -- please wait/ || /^\s/) {
			# ignore
		}
		else {
			warn "Unexpected output from $list_cmd line $.:\n$_";
		}
	}
	close( PIPE );
}

open( F, ">$reported_file" )
	or die "Cannot open $reported_file for writing: $!\n";
foreach $dist (qw(stable frozen unstable)) {
	foreach (keys %{$reported{$dist}}) {
		print F "$_ $dist $reported{$dist}->{$_}\n"
			if $seen{$dist}->{$_};
	}
}
close( F );

exit 0;

sub check {
	my ($dist, $pkg, $builder, $bdate) = @_;
	my $date = (exists $reported{$dist}->{$pkg}) ?
		$reported{$dist}->{$pkg} : $bdate;

	if ($now - $date > $report_time) {
		notify_mail( $dist, $pkg, $builder, $bdate );
		$reported{$dist}->{$pkg} = $now;
	}
}

sub notify_mail {
	my ($dist, $pkg, $to, $_date) = @_;
	my $date = localtime($date);
	local( *MAIL );
	
	local $SIG{'PIPE'} = 'IGNORE';
	open( MAIL,  "| $mailprog -oem $to\@$mailname" )
		or die "Can't open pipe to $mailprog: $!\n";
	print MAIL <<"EOF";
From: $sender\@$mailname
To: $to\@$mailname
Subject: Old build of $pkg (dist=$dist)

The package $pkg has been taken by you for
building in distribution $dist at $date.
This is some time ago now, so it could be you have forgotten the build.
Can you please check this and --if this is the case-- give back the package
or finish it?
If you did not call wanna-build --uploaded, it might also be the case
that the package isn't installed yet in the archive.
	
(This is an automated message.)
EOF
	close( MAIL );
	
}

sub parse_date {
	my $text = shift;

	die "Cannot parse date: $text\n"
		if $text !~ /^(\d{4}) (\w{3}) (\d+) (\d{2}):(\d{2}):(\d{2})$/;
	my ($year, $mon, $day, $hour, $min, $sec) = ($1, $2, $3, $4, $5, $6);
	$mon =~ y/A-Z/a-z/;
	die "Invalid month name $mon" if !exists $monname{$mon};
	$mon = $monname{$mon};
	return timelocal($sec, $min, $hour, $day, $mon, $year);
}