Added some code to peer into a data structure in Maemian/Schedule.pm. Also added the
[maemian] / nokia-lintian / collection / diffstat
1 #!/usr/bin/perl -w
2 # diffstat -- lintian 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 lintian 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 my $LINTIAN_ROOT = $ENV{'LINTIAN_ROOT'} || '/usr/share/lintian';
31
32 ($#ARGV == 1) or fail("syntax: diffstat <pkg>");
33 my $pkg = shift;
34
35 -f "fields/version" or fail("diffstat invoked in wrong directory");
36
37 open (V, '<', "fields/version") or fail("cannot open fields/version: $!");
38 my $ver = <V>; chomp $ver;
39 close V;
40
41 $ver =~ s/^\d://; #Remove epoch for this
42
43 my $diff_file = "${pkg}_${ver}.diff.gz";
44 unless (-f $diff_file) {
45 # we have to write an empty file so that the checks don't crap out. <sigh>
46   open (D, '>', "diffstat"); close D;
47   exit 0;
48 }
49
50 use lib "$ENV{'LINTIAN_ROOT'}/lib";
51 use Pipeline;
52 pipeline((sub { exec('gzip', '-dc', $diff_file); }),
53          "debian-patch"
54         );
55
56 open (STAT, '>', "diffstat") or fail("cannot open scripts output file: $!");
57 # diffstat is noisy on stderr if its stdout is not a tty.
58 # Shut it up by redirecting stderr to /dev/null.
59 open STDERR, ">/dev/null";
60 open (DIFF, '-|', qw/diffstat -p1 debian-patch/)
61   or fail("cannot open pipe to diffstat on debian-patch: $!");
62 # Copy all except last line to the STAT file
63 my $previous;
64 while (<DIFF>) {
65     print STAT $previous if $previous;
66     $previous = $_;
67 }
68 close DIFF or fail("cannot close pipe to diffstat on debian-patch: $!");
69 close STAT or fail("error writing diffstat file: $!");
70
71 exit 0;
72
73 # -----------------------------------
74
75 sub fail {
76     if ($_[0]) {
77         print STDERR "internal error: $_[0]\n";
78     } elsif ($!) {
79         print STDERR "internal error: $!\n";
80     } else {
81         print STDERR "internal error.\n";
82     }
83     exit 1;
84 }