#!/usr/bin/perl # # vlog: little utility to watch the logs written by sbuild # Copyright (C) 1999 Roman Hodek # # 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # # $Id$ # use POSIX; ($main::HOME = $ENV{'HOME'}) or die "HOME not defined in environment!\n"; $logpath = "$main::HOME/logs"; while( 1 ) { my $curr_pkg = read_progress(); if (!$curr_pkg) { print "No build-progress -- waiting\n"; do { sleep 5; } while (!($curr_pkg = read_progress())); } my $logf = newest_log( "$logpath/${curr_pkg}_*" ); print "\n\n", "="x78, "\n$logf:\n\n"; tail( $logf ); } sub read_progress { my $f = "$main::HOME/build/build-progress"; my $p = ""; open( F, "<$f" ) || return ""; while( ) { $p = $1 if /^(\S+): currently building/; } close( F ); return $p; } sub newest_log { my $pattern = shift; my @f = glob( $pattern ); my $maxtime = 0; my $f = ""; my @s; foreach (@f) { @s = stat( $_ ); warn "Cannot stat $_: $!", next if !@s; if ($s[9] > $maxtime) { $maxtime = $s[9]; $f = $_; } } return $f; } sub tail { my $f = shift; my @s = stat( $f ); if (!@s) { warn "Cannot stat $f: $!\n"; return; } my $size = $s[7]; if (!open( F, "<$f" )) { warn "Cannot open $f: $!\n"; return; } if ($size > 3*1024) { seek( F, -3*1024, SEEK_END ); my $junk = ; # throw away first incomplete line print $size+3*1024, " bytes skipped...\n"; } while( 1 ) { while( ) { print $_; if (/^Build needed \d\d:\d\d:\d\d/) { close( F ); return; } } sleep( 2 ); } }