1 # Copyright (C) 2008 Frank Lichtenheld <frank@lichtenheld.de>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, you can find it on the World Wide
15 # Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
16 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 package Lintian::Schedule;
27 my ($class, %options) = @_;
32 $self->{opts} = \%options;
33 $self->{schedule} = [];
39 # schedule a package for processing
41 my ($self, $type, $file, %pkg_info) = @_;
43 my ($pkg, $ver, $arch);
46 (@pkg_info{qw(source version)}, 'source');
49 @pkg_info{qw(package version architecture)};
55 my $s = "$type $pkg $ver $arch $file";
56 my %h = ( type => $type, package => $pkg, version => $ver,
57 architecture => $arch, file => $file );
59 if ( $self->{unique}{$s}++ ) {
60 if ($self->{opts}{verbose}) {
61 printf "N: Ignoring duplicate %s package $pkg (version $ver)\n",
62 $type eq 'b' ? 'binary' : ($type eq 's' ? 'source': 'udeb');
67 push(@{$self->{schedule}}, \%h);
72 my ($self, $type, $file) = @_;
74 my $info = get_deb_info($file);
75 return unless defined $info;
76 return $self->add_file($type, $file, %$info);
80 my ($self, $file) = @_;
82 my $info = get_dsc_info($file);
83 return unless defined $info;
84 return $self->add_file('s', $file, %$info);
88 my ($self, $packages_file) = @_;
90 open(IN, '<', $packages_file)
91 or die("cannot open packages file $packages_file for reading: $!");
94 my ($type, $pkg, $ver, $file) = split(/\s+/, $_, 4);
96 $self->add_file($type, $file, source => $pkg, version => $ver);
98 $self->add_file($type, $file, package => $pkg, version => $ver);
104 # for each package (the sort is to make sure that source packages are
105 # before the corresponding binary packages--this has the advantage that binary
106 # can use information from the source packages if these are unpacked)
107 my %type_sort = ('b' => 1, 'u' => 1, 's' => 2 );
109 return sort({$type_sort{$b->{type}} <=> $type_sort{$a->{type}}}
110 @{$_[0]->{schedule}});
114 return scalar @{$_[0]->{schedule}};