]> git.deb.at Git - deb/packages.git/blob - lib/Packages/DoNewPkg.pm
Replace non working volatile mirror debian.domainmail.org with mirror.csclub.uwaterloo.ca
[deb/packages.git] / lib / Packages / DoNewPkg.pm
1 package Packages::DoNewPkg;
2
3 use strict;
4 use warnings;
5
6 use POSIX;
7 use CGI ();
8 use Exporter;
9 our @ISA = qw( Exporter );
10 our @EXPORT = qw( do_newpkg );
11
12 use Packages::Search qw( :all );
13 use Packages::CGI;
14 use Packages::DB;
15 use Packages::Config qw( $TOPDIR @SECTIONS $ROOT );
16
17 sub do_newpkg {
18     my ($params, $opts, $page_content) = @_;
19     my $cat = $opts->{cat};
20
21     if ($params->{errors}{suite}) {
22         fatal_error( $cat->g( "suite not valid or not specified" ) );
23     }
24     if (@{$opts->{suite}} > 1) {
25         fatal_error( $cat->g( "more than one suite specified for newpkg (%s)",
26                               "@{$opts->{suite}}" ) );
27     }
28
29     my $sort_func = sub { $_[0][0] cmp $_[1][0] };
30     $sort_func = sub { $_[0][1] <=> $_[1][1] or $_[0][0] cmp $_[1][0] }
31         if $opts->{mode} eq 'byage';
32
33     my $suite = $opts->{suite}[0];
34     my $one_archive = @{$opts->{archive}} == 1 ?
35         $opts->{archive}[0] : undef;
36     my $one_section = @{$opts->{section}} == 1 ?
37         $opts->{section}[0] : undef;
38
39     my @new_pkgs;
40     open NEWPKG, '<', "$TOPDIR/files/packages/newpkg_info_$suite"
41         or do {
42             warn "can't read newpkg_info_$suite: $!";
43             fatal_error( $cat->g("no newpkg information found for suite %s",
44                                  $suite) );
45             return;
46     };
47     while (<NEWPKG>) {
48         chomp;
49         my @data = split /\s/, $_, 11;
50
51         next unless $data[2]; #removed packages
52         next unless $data[3] eq $suite;
53         next if $one_archive and $data[2] ne $one_archive;
54         next if $one_section and $data[5] ne $one_section;
55
56         debug( "new pkg: @data", 1 ) if DEBUG;
57         push @new_pkgs, \@data;
58     }
59     close NEWPKG;
60     
61     (my @date)= gmtime();
62     #FIXME: compute in the template
63     $page_content->{rss_timestamp} = strftime ("%Y-%m-%dT%H:%M+00:00", @date);
64
65     if (@new_pkgs) {
66         $page_content->{new_packages} = [ sort { &$sort_func($a,$b) } @new_pkgs ];
67     }
68
69     $page_content->{suite} = $suite;
70     $page_content->{section} = $one_section if $one_section;
71     $page_content->{archive} = $one_archive if $one_archive;
72     $page_content->{sections} = \@SECTIONS;
73
74 }
75
76 1;