Added lots more modules from lintian. Maemian appears to work.
[maemian] / collection / diffstat
1 #!/usr/bin/perl -w
2 # diffstat -- maemian collection script for source packages
3
4 # Copyright (C) 1998 Richard Braakman
5
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.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, you can find it on the World Wide
18 # Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
19 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
20 # MA 02110-1301, USA.
21
22 # This could be written more easily in shell script, but I'm trying
23 # to keep everything as perl to cut down on the number of processes
24 # that need to be started in a maemian scan.  Eventually all the
25 # perl code will be perl modules, so only one perl interpreter
26 # need be started.
27
28 use strict;
29
30 use lib "$ENV{'MAEMIAN_ROOT'}/lib";
31 use Util;
32
33 ($#ARGV == 1) or fail("syntax: diffstat <pkg>");
34 my $pkg = shift;
35
36 -f "fields/version" or fail("diffstat invoked in wrong directory");
37
38 open (V, '<', "fields/version") or fail("cannot open fields/version: $!");
39 my $ver = <V>; chomp $ver;
40 close V;
41
42 unlink('debian-patch');
43
44 $ver =~ s/^\d://; #Remove epoch for this
45
46 my $diff_file = "${pkg}_${ver}.diff.gz";
47 unless (-f $diff_file) {
48 # we have to write an empty file so that the checks don't crap out. <sigh>
49   touch_file('diffstat');
50   exit 0;
51 }
52
53 gunzip_file($diff_file, "debian-patch");
54
55 open (STAT, '>', "diffstat") or fail("cannot open scripts output file: $!");
56 # diffstat is noisy on stderr if its stdout is not a tty.
57 # Shut it up by redirecting stderr to /dev/null.
58 open STDERR, ">/dev/null";
59 open (DIFF, '-|', qw/diffstat -p1 debian-patch/)
60   or fail("cannot open pipe to diffstat on debian-patch: $!");
61 # Copy all except last line to the STAT file
62 my $previous;
63 while (<DIFF>) {
64     print STAT $previous if $previous;
65     $previous = $_;
66 }
67 close DIFF or fail("cannot close pipe to diffstat on debian-patch: $!");
68 close STAT or fail("error writing diffstat file: $!");