/usr/share/perl5/Lintian/ProcessablePool.pm is in lintian 2.5.81ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | # Copyright (C) 2011 Niels Thykier <niels@thykier.net>
#
# 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, you can find it on the World Wide
# Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301, USA.
## Represents a pool of processables (Lintian::Processable)
package Lintian::ProcessablePool;
use strict;
use warnings;
use Carp qw(croak);
use Cwd();
use Lintian::Util;
use Lintian::Processable::Package;
use Lintian::ProcessableGroup;
=head1 NAME
Lintian::ProcessablePool -- Pool of processables
=head1 SYNOPSIS
use Lintian::ProcessablePool;
my $pool = Lintian::ProcessablePool->new;
$pool->add_file('foo.changes');
$pool->add_file('bar.dsc');
$pool->add_file('baz.deb');
$pool->add_file('qux.buildinfo');
foreach my $gname ($pool->get_group_names){
my $group = $pool->get_group($gname);
process($gname, $group);
}
=head1 METHODS
=over 4
=item Lintian::ProcessablePool->new ([LAB])
Creates a new empty pool.
If LAB is given, it is assumed to be a Lintian::Lab. In this case,
any processable added to this pool will be stored as a
L<lab entry|Lintian::Lab::Entry> from LAB.
=cut
sub new {
my ($class, $lab) = @_;
my $self = {
'lab' => $lab,
'groups' => {},
};
bless $self, $class;
return $self;
}
=item $pool->add_file($file)
Adds a file to the pool. The $file will be turned into a
L<processable|Lintian::Processable> and grouped together with other
processables from the same source package (if any).
=cut
sub add_file {
my ($self, $file) = @_;
if ($file =~ m/\.(buildinfo|changes)$/o){
my $type = $1;
croak "$file does not exist" unless -f $file;
my $pkg_path = Cwd::abs_path($file);
croak "Cannot resolve $file: $!" unless $pkg_path;
return $self->_add_file($type, $pkg_path);
}
my $proc = Lintian::Processable::Package->new($file);
return $self->add_proc($proc);
}
=item $pool->add_proc ($proc)
Adds a L<processable|Lintian::Processable> to the pool.
=cut
sub add_proc {
my ($self, $proc) = @_;
my ($group, $groupid);
my $pkg_type = $proc->pkg_type;
if ($proc->tainted) {
warn(
sprintf(
"warning: tainted %1\$s package '%2\$s', skipping\n",
$pkg_type, $proc->pkg_name
));
return 0;
}
$groupid = $self->_get_group_id($proc);
$group = $self->{groups}{$groupid};
if (defined $group){
if ($pkg_type eq 'source'){
# if this is a source pkg, then this is a duplicate
# assuming the group already has a source package.
return 0 if defined $group->get_source_processable;
}
# else add the binary/udeb proc to the group
return $group->add_processable($proc);
} else {
# Create a new group
$group = Lintian::ProcessableGroup->new($self->{'lab'});
$group->add_processable($proc);
$self->{groups}{$groupid} = $group;
}
# add it to the "unprocessed"/"seen" map.
return 1;
}
=item $pool->get_group_names
Returns the name of all the groups in this pool.
Do not modify the list nor its contents.
=cut
sub get_group_names{
my ($self) = @_;
return keys %{ $self->{groups} };
}
=item $pool->get_group($name)
Returns the group called $name or C<undef>
if there is no group called $name.
=cut
sub get_group{
my ($self, $group) = @_;
return $self->{groups}{$group};
}
=item $pool->get_groups
Returns all the groups in the pool.
Do not modify the list nor its contents.
=cut
sub get_groups{
my ($self) = @_;
my $groups = $self->{groups};
if (scalar keys %$groups) {
return values %$groups;
}
return ();
}
=item $pool->empty
Returns true if the pool is empty.
=cut
sub empty{
my ($self) = @_;
return scalar keys %{ $self->{groups} } < 1;
}
#### Internal subs ####
sub _add_file{
my ($self, $type, $pkg_path) = @_;
my $group = Lintian::ProcessableGroup->new($self->{'lab'}, $pkg_path);
my $proc;
if ($type eq 'buildinfo') {
$proc = $group->get_buildinfo_processable;
} elsif ($type eq 'changes') {
$proc = $group->get_changes_processable;
}
my $gid = $self->_get_group_id($proc);
my $ogroup = $self->{groups}{$gid};
if (defined($ogroup)){
# Group already exists...
my $added = 0;
# Merge architectures/packages ...
# Accept all new
if ($type eq 'buildinfo'
&& !defined($ogroup->get_buildinfo_processable)) {
$ogroup->add_processable($proc);
$added = 1;
}elsif ($type eq 'changes'
&& !defined($ogroup->get_changes_processable)) {
$ogroup->add_processable($proc);
$added = 1;
}
if ( !defined $ogroup->get_source_processable
&& defined $group->get_source_processable){
$ogroup->add_processable($group->get_source_processable);
$added = 1;
}
foreach my $bin ($group->get_binary_processables){
# New binary package ?
my $was_new = $ogroup->add_processable($bin);
$added ||= $was_new;
}
return $added;
} else {
$self->{groups}{$gid} = $group;
}
return 1;
}
# Fetches the group id for a package
# - this id is based on the name and the version of the
# src-pkg.
sub _get_group_id{
my ($self, $pkg) = @_;
my $id = $pkg->pkg_src;
$id .= '/' . $pkg->pkg_src_version;
return $id;
}
=back
=head1 AUTHOR
Originally written by Niels Thykier <niels@thykier.net> for Lintian.
=head1 SEE ALSO
lintian(1)
L<Lintian::Processable>
L<Lintian::ProcessableGroup>
=cut
1;
# Local Variables:
# indent-tabs-mode: nil
# cperl-indent-level: 4
# End:
# vim: syntax=perl sw=4 sts=4 sr et
|