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 Maemian::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);
71 # add_deb takes the name of a binary deb and the letter "b" as args.
73 my ($self, $type, $file) = @_;
75 my $info = get_deb_info($file);
76 # use the following code to peer into the control file of the deb
77 # print map { $_, ": ",
78 # %$info->{$_} . "\n" } keys %$info;
79 return unless defined $info;
80 return $self->add_file($type, $file, %$info);
84 my ($self, $file) = @_;
86 my $info = get_dsc_info($file);
87 return unless defined $info;
88 return $self->add_file('s', $file, %$info);
92 my ($self, $packages_file) = @_;
94 open(IN, '<', $packages_file)
95 or die("cannot open packages file $packages_file for reading: $!");
98 my ($type, $pkg, $ver, $file) = split(/\s+/, $_, 4);
100 $self->add_file($type, $file, source => $pkg, version => $ver);
102 $self->add_file($type, $file, package => $pkg, version => $ver);
108 # for each package (the sort is to make sure that source packages are
109 # before the corresponding binary packages--this has the advantage that binary
110 # can use information from the source packages if these are unpacked)
111 my %type_sort = ('b' => 1, 'u' => 1, 's' => 2 );
113 return sort({$type_sort{$b->{type}} <=> $type_sort{$a->{type}}}
114 @{$_[0]->{schedule}});
118 return scalar @{$_[0]->{schedule}};