1 package Packages::DoNewPkg;
6 use Benchmark ':hireswallclock';
12 our @ISA = qw( Exporter );
13 our @EXPORT = qw( do_newpkg );
15 use Packages::I18N::Locale;
16 use Packages::Search qw( :all );
19 use Packages::Config qw( $TOPDIR @SECTIONS $HOSTNAME $ROOT );
22 my ($params, $opts, $html_header, $menu, $page_content) = @_;
24 if ($params->{errors}{suite}) {
25 fatal_error( _g( "suite not valid or not specified" ) );
27 if (@{$opts->{suite}} > 1) {
28 fatal_error( sprintf( _g( "more than one suite specified for show (%s)" ), "@{$opts->{suite}}" ) );
31 my $sort_func = sub { $_[0][0] cmp $_[1][0] };
32 $sort_func = sub { $_[0][1] <=> $_[1][1] or $_[0][0] cmp $_[1][0] }
33 if $opts->{mode} eq 'byage';
35 my $suite = $opts->{suite}[0];
36 my $one_archive = @{$opts->{archive}} == 1 ?
37 $opts->{archive}[0] : undef;
38 my $one_section = @{$opts->{section}} == 1 ?
39 $opts->{section}[0] : undef;
41 my @full_path = ($HOSTNAME, $ROOT, $suite);
42 push @full_path, $one_archive if $one_archive;
43 my $full_path = join( '/', @full_path );
46 #FIXME: move to Packages::DB?
47 open NEWPKG, '<', "$TOPDIR/files/packages/newpkg_info"
48 or die "can't read newpkg_info file: $!";
51 my @data = split /\s/, $_, 10;
53 next unless $data[3] eq $suite;
54 next if $one_archive and $data[2] ne $one_archive;
55 next if $one_section and $data[5] ne $one_section;
57 debug( "new pkg: @data", 1 ) if DEBUG;
58 push @new_pkgs, \@data;
63 my $now_time = strftime ("%B %d, %Y", @date);
64 my $rss_time = strftime ("%Y-%m-%dT%H:%M+00:00", @date);
66 unless ($opts->{format} eq 'rss') {
67 my $title = sprintf( _g( "New Packages in \"%s\"" ),
69 %$html_header = ( title => $title,
70 title_keywords => "debian, "._g('new packages').", $suite, @{$opts->{section}}",
71 meta => "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS\" href=\"newpkg?format=rss\">",
72 lang => $opts->{lang},
75 $$page_content .= "<p>"
76 . sprintf(_g( "The following packages were added to suite <em>%s</em>%s in the Debian archive during the last 7 days."), $suite,
77 $one_section ? sprintf(_g(" (section %s)"),$one_section):'')."</p>"
78 . "<p>".sprintf( _g( "This information is also available as an <a href=\"%s\">RSS feed</a>." ), "newpkg?format=rss" )
79 ." <a href=\"newpkg?format=rss\"><img src=\"http://planet.debian.org/rss10.png\" alt=\"[RSS 1.0 Feed]\"></a></p>";
82 $$page_content .= "\n<ul>\n";
84 foreach my $pkg (sort { &$sort_func($a,$b) } @new_pkgs) {
85 $$page_content .= sprintf ("<li><a href=\"%s\">%s</a>\n -- %s%s",
87 encode_entities($pkg->[-1], '"&<>'),
89 sprintf(_g(" <em>(%s days old)</em>"),$pkg->[1]):
92 $$page_content .= "\n</ul>\n" if @new_pkgs;
97 foreach my $s (@SECTIONS) {
98 $slist .= ", " if $slist;
99 $slist .= $one_section eq $s ? $s :
100 "<a href=\"../$s/newpkg\">$s</a>";
104 $$page_content .= '<p class="psmallcenter"><a href="$ROOT/$suite/allpackages" title="'.
105 _g( "List of all packages" ) ."\">".
106 _g( "All packages" ) ."</a><br>(<a href=\"$ROOT/$suite/allpackages?format=txt\">".
107 _g( "compact compressed textlist" )."</a>)<br>".
108 ($slist ? sprintf(_g( "New packages in %s" ), $slist ):'').
111 } else { # unless ($opts->{format} eq 'rss')
112 my ( $rss_link, $rss_description, $rss_date );
114 $rss_description = sprintf(_g( "The following packages were added to suite %s%s in the Debian archive during the last 7 days."), $suite,
115 $one_section ? sprintf(_g(" (section %s)"),$one_section):'');
117 my $rss = new XML::RSS (version => '1.0');
118 $rss_link = "$full_path".($one_section?"$one_section/":'')."/newpkg?format=rss";
120 title => _g("New Debian Packages"),
122 description => $rss_description,
125 publisher => 'debian-www@lists.debian.org',
126 rights => 'Copyright '.($date[5]+1900).', SPI Inc.',
127 language => $opts->{lang},
130 updatePeriod => "daily",
131 updateFrequency => "2",
132 # updateBase => "1901-01-01T00:00+00:00",
135 foreach my $pkg (sort { &$sort_func($a,$b) } @new_pkgs) {
138 link => "$full_path/$pkg->[0]",
139 description => $pkg->[-1],
141 subject => $pkg->[6],
144 my $charset = get_charset( $opts->{lang} );
145 print &CGI::header( -type => 'application/rss+xml',
146 -charset => $charset );
147 print $rss->as_string;