X-Git-Url: https://git.deb.at/?p=deb%2Fpackages.git;a=blobdiff_plain;f=lib%2FPackages%2FDoDownload.pm;h=bc7dbab0e6d57a78783f81ede244f65e76cc6876;hp=87bc10ccbfe12fb5520f8a284b273ef104980ce8;hb=10253a9c867f3036137ef5ed5379da930ef04c20;hpb=d9c10aaf0bb03bfb75404f9041967b9f91012bdb diff --git a/lib/Packages/DoDownload.pm b/lib/Packages/DoDownload.pm index 87bc10c..bc7dbab 100644 --- a/lib/Packages/DoDownload.pm +++ b/lib/Packages/DoDownload.pm @@ -3,215 +3,40 @@ package Packages::DoDownload; use strict; use warnings; +use POSIX; use CGI (); use DB_File; use Benchmark ':hireswallclock'; use Exporter; use Deb::Versions; -use Packages::HTML (); +use Packages::I18N::Locale; use Packages::Search qw( :all ); -use Packages::Config qw( $HOME $DBDIR @SUITES @ARCHIVES @SECTIONS @ARCHITECTURES ); +use Packages::Config qw( $DBDIR @SUITES @ARCHIVES @SECTIONS @ARCHITECTURES ); use Packages::CGI; use Packages::DB; our @ISA = qw( Exporter ); our @EXPORT = qw( do_download ); -# TODO: find a way to get the U.S. mirror list from a more authoritive -# location automatically. might not be overly smart to automatize it -# completely, since I hand pick sites that are up-to-date, fast, and -# have HTTP on a reasonably short URL -# -- Joy - -# hint: -# grep-dctrl -F Site,Alias -e '(udel|bigfoot|kernel|crosslink|internap|cerias|lcs.mit|progeny)' Mirrors.masterlist | timestamps/archive_mirror_check.py -our @north_american_sites = ( - "ftp.us.debian.org/debian", - "http.us.debian.org/debian", - "ftp.debian.org/debian", -# "ftp.ca.debian.org/debian", - "ftp.egr.msu.edu/debian", - "mirrors.kernel.org/debian", - "archive.progeny.com/debian", - "debian.crosslink.net/debian", - "ftp-mirror.internap.com/pub/debian", - "ftp.cerias.purdue.edu/pub/os/debian", - "ftp.lug.udel.edu/debian", - "debian.lcs.mit.edu/debian", - "debian.teleglobe.net", - "debian.rutgers.edu", - "debian.oregonstate.edu/debian", - ); -our @european_sites = ( - "ftp.de.debian.org/debian", - "ftp.at.debian.org/debian", - "ftp.bg.debian.org/debian", - "ftp.cz.debian.org/debian", - "ftp.dk.debian.org/debian", - "ftp.ee.debian.org/debian", - "ftp.fi.debian.org/debian", - "ftp.fr.debian.org/debian", - "ftp.hr.debian.org/debian", - "ftp.hu.debian.org/debian", - "ftp.ie.debian.org/debian", - "ftp.is.debian.org/debian", - "ftp.it.debian.org/debian", - "ftp.nl.debian.org/debian", - "ftp.no.debian.org/debian", - "ftp.pl.debian.org/debian", - "ftp.si.debian.org/debian", - "ftp.es.debian.org/debian", - "ftp.se.debian.org/debian", - "ftp.tr.debian.org/debian", - "ftp.uk.debian.org/debian", - ); -our @south_american_sites = ( - "ftp.br.debian.org/debian", - "ftp.cl.debian.org/debian", - ); -our @australian_sites = ( - "ftp.au.debian.org/debian", - "ftp.wa.au.debian.org/debian", - "ftp.nz.debian.org/debian", - ); -our @asian_sites = ( - "ftp.jp.debian.org/debian", -# "ftp.kr.debian.org/debian", - "linux.csie.nctu.edu.tw/debian", - "debian.linux.org.tw/debian", - "linux.cdpa.nsysu.edu.tw/debian", - ); - -our @volatile_european_sites = ( - "volatile.debian.net/debian-volatile", - "ftp2.de.debian.org/debian-volatile", - "ftp.sk.debian.org/debian-volatile", - ); -our @backports_european_sites = ( - "www.backports.org/debian", - "debian.sil.at/backports.org/", - "backports.debian.or.at/backports.org", - "mirror.realroute.net/backports.org", - "backports.cisbg.com", - "backports.linuxdediziert.de/backports.org", - "debian.netcologne.de/debian-backports", - "ftp.de.debian.org/backports.org", - "mirror.buildd.net/backports.org", - "ftp.estpak.ee/backports.org", - "debian.acantho.net/backports.org", - "backports.essentkabel.com/backports.org", - "backports.sipo.nl", - "ftp.tuke.sk", - ); -our @backports_asian_sites = ( - "backports.mithril-linux.org", - ); -our @backports_australian_sites = ( - "mirror.linux.org.au/backports.org", - ); -our @amd64_european_sites = ( - "amd64.debian.net/debian", - "ftp.de.debian.org/debian-amd64/debian", - "bach.hpc2n.umu.se/debian-amd64/debian", - "bytekeeper.as28747.net/debian-amd64/debian", - "mirror.switch.ch/debian-amd64/debian", - "ftp.nl.debian.org/debian-amd64/debian", - ); -our @amd64_asian_sites = ( - "hanzubon.jp/debian-amd64/debian", - ); -our @amd64_north_american_sites = ( - "mirror.espri.arizona.edu/debian-amd64/debian", - ); -our @kfreebsd_north_american_sites = ( - "www.gtlib.gatech.edu/pub/gnuab/debian", - ); -our @kfreebsd_european_sites = ( - # master site, aka ftp.gnuab.org - "kfreebsd-gnu.debian.net/debian", - "ftp.easynet.be/ftp/gnuab/debian", - "ftp.de.debian.org/debian-kfreebsd", - ); -our @nonus_north_american_sites = ( -# "ftp.ca.debian.org/debian-non-US", - "debian.yorku.ca/debian/non-US", - "mirror.direct.ca/linux/debian-non-US", - ); -our @nonus_european_sites = ( - "non-us.debian.org/debian-non-US", - "ftp.de.debian.org/debian-non-US", - "ftp.at.debian.org/debian-non-US", - "ftp.bg.debian.org/debian-non-US", - "ftp.cz.debian.org/debian-non-US", - "ftp.fi.debian.org/debian-non-US", - "ftp.fr.debian.org/debian-non-US", - "ftp.hr.debian.org/debian-non-US", - "ftp.hu.debian.org/debian-non-US", - "ftp.ie.debian.org/debian-non-US", - "ftp.is.debian.org/debian-non-US", - "ftp.it.debian.org/debian-non-US", - "ftp.nl.debian.org/debian-non-US", - "ftp.no.debian.org/debian-non-US", - "ftp.pl.debian.org/debian/non-US", - "ftp.si.debian.org/debian-non-US", - "ftp.es.debian.org/debian-non-US", - "ftp.se.debian.org/debian-non-US", - "ftp.tr.debian.org/debian-non-US", - "ftp.uk.debian.org/debian/non-US", - ); -our @nonus_australian_sites = ( - "ftp.au.debian.org/debian-non-US", - "ftp.wa.au.debian.org/debian-non-US", - "ftp.nz.debian.org/debian-non-US", - ); -our @nonus_asian_sites = ( - "ftp.jp.debian.org/debian-non-US", -# "ftp.kr.debian.org/debian-non-US", - "linux.csie.nctu.edu.tw/debian-non-US", - "debian.linux.org.tw/debian-non-US", - "linux.cdpa.nsysu.edu.tw/debian-non-US", - ); -our @nonus_south_american_sites = ( - "ftp.br.debian.org/debian-non-US", - "ftp.cl.debian.org/debian-non-US", - ); - -# list of architectures -our %arches = ( - i386 => 'Intel x86', - m68k => 'Motorola 680x0', - sparc => 'SPARC', - alpha => 'Alpha', - powerpc => 'PowerPC', - arm => 'ARM', - hppa => 'HP PA-RISC', - ia64 => 'Intel IA-64', - mips => 'MIPS', - mipsel => 'MIPS (DEC)', - s390 => 'IBM S/390', - "hurd-i386" => 'Hurd (i386)', - amd64 => 'AMD64', - "kfreebsd-i386" => 'GNU/kFreeBSD (i386)' -); sub do_download { - my ($params, $opts, $html_header, $menu, $page_content) = @_; + my ($params, $opts, $page_content) = @_; if ($params->{errors}{package}) { - fatal_error( "package not valid or not specified" ); + fatal_error( _g( "package not valid or not specified" ) ); } if ($params->{errors}{suite}) { - fatal_error( "suite not valid or not specified" ); + fatal_error( _g( "suite not valid or not specified" ) ); } if ($params->{errors}{arch}) { - fatal_error( "arch not valid or not specified" ); + fatal_error( _g( "architecture not valid or not specified" ) ); } if (@{$opts->{suite}} > 1) { - fatal_error( "more than one suite specified for download (@{$opts->{suite}})" ); + fatal_error( sprintf( _g( "more than one suite specified for download (%s)" ), "@{$opts->{suite}}" ) ); } if (@{$opts->{arch}} > 1) { - fatal_error( "more than one architecture specified for download (@{$opts->{arch}})" ); + fatal_error( sprintf( _g( "more than one architecture specified for download (%s)" ), "@{$opts->{arch}}" ) ); } $opts->{h_sections} = { map { $_ => 1 } @SECTIONS }; @@ -221,9 +46,7 @@ sub do_download { our (%packages_all); my (@results); - my ($final_result, $file, $filen, $md5sum, @file_components, $archive) = ("")x5; - - sub gettext { return $_[0]; }; + my ($final_result, $filename, $directory, @file_components, $archive) = ("")x5; my $st0 = new Benchmark; unless (@Packages::CGI::fatal_errors) { @@ -233,9 +56,10 @@ sub do_download { read_entry( \%packages, $pkg, \@results, $opts ); + @results = grep { $_->[7] ne 'v' } @results; unless (@results) { - fatal_error( "No such package". - "{insert link to search page with substring search}" ); +# fatal_error( _g( "No such package." )."
". +# sprintf( _g( 'Search for the package' ), "$SEARCH_URL/$pkg" ) ); } else { my $final_result = shift @results; foreach (@results) { @@ -244,164 +68,43 @@ sub do_download { } } + debug( "final_result=@$final_result", 1 ); $archive = $final_result->[1]; my %data = split /\000/, $packages_all{"$pkg $arch $final_result->[7]"}; - $file = $data{filename}; - @file_components = split('/', $file); - $filen = pop(@file_components); - - $md5sum = $data{md5sum}; - } - } - - my $arch_string = $arch ne 'all' ? "on $arches{$arch} machines" : ""; - - %$html_header = ( title => "Package Download Selection", - lang => "en", - print_title => 1 ); - - if ($file) { - $$page_content .= "

Download Page for $filen $arch_string

\n". - "

You can download the requested file from the "; - $$page_content .= join( '/', @file_components).'/'; - $$page_content .= " subdirectory at"; - $$page_content .= $archive ne 'security' ? " any of these sites:" : ":"; - $$page_content .= "

\n"; - - if ($archive eq 'security') { - - $$page_content .= < -
  • security.debian.org/debian-security
  • - - -

    Debian security updates are currently officially distributed only via - security.debian.org.

    -END -; - } elsif ($arch eq 'amd64') { - - $$page_content .= print_links( "North America", $file, @amd64_north_american_sites ); - $$page_content .= print_links( "Europe", $file, @amd64_european_sites ); -# $$page_content .= print_links( "Australia and New Zealand", $file, -# @nonus_australian_sites ); - $$page_content .= print_links( "Asia", $file, @amd64_asian_sites ); -# $$page_content .= print_links( "South America", $file, @nonus_south_american_sites ); - - $$page_content .= <Note that AMD64 is not officialy included in the Debian archive - yet, but the AMD64 porter group keeps their archive in sync with - the official archive as close as possible. See the - AMD64 ports page for - current information.

    -END -; - } elsif ($arch eq 'kfreebsd-i386') { - - $$page_content .= print_links( "North America", $file, @kfreebsd_north_american_sites ); - $$page_content .= print_links( "Europe", $file, @kfreebsd_european_sites ); -# $$page_content .= print_links( "Australia and New Zealand", $file, -# @nonus_australian_sites ); -# $$page_content .= print_links( "Asia", $file, @amd64_asian_sites ); -# $$page_content .= print_links( "South America", $file, @nonus_south_american_sites ); - - $$page_content .= <Note that GNU/kFreeBSD is not officialy included in the Debian archive - yet, but the GNU/kFreeBSD porter group keeps their archive in sync with - the official archive as close as possible. See the - GNU/kFreeBSD ports page for - current information.

    -END -; - } elsif ($archive eq 'non-US') { - - $$page_content .= print_links( "North America", $file, @nonus_north_american_sites ); - $$page_content .= print_links( "Europe", $file, @nonus_european_sites ); - $$page_content .= print_links( "Australia and New Zealand", $file, - @nonus_australian_sites ); - $$page_content .= print_links( "Asia", $file, @nonus_asian_sites ); - $$page_content .= print_links( "South America", $file, @nonus_south_american_sites ); - - $$page_content .= <If none of the above sites are fast enough for you, please see our - complete mirror list.

    -END -; - } elsif ($archive eq 'backports') { - -# $$page_content .= print_links( "North America", $file, @nonus_north_american_sites ); - $$page_content .= '
    '; - $$page_content .= print_links( "Europe", $file, @backports_european_sites ); - $$page_content .= '
    '; - $$page_content .= print_links( "Australia and New Zealand", $file, - @backports_australian_sites ); - $$page_content .= print_links( "Asia", $file, @backports_asian_sites ); -# $$page_content .= print_links( "South America", $file, @nonus_south_american_sites ); - $$page_content .= '
    '; - - $$page_content .= <If none of the above sites are fast enough for you, please see our - complete mirror list.

    -END -; - } elsif ($archive eq 'volatile') { - -# $$page_content .= print_links( "North America", $file, @nonus_north_american_sites ); - $$page_content .=_links( "Europe", $file, @volatile_european_sites ); -# $$page_content .= print_links( "Australia and New Zealand", $file, -# @nonus_australian_sites ); -# $$page_content .= print_links( "Asia", $file, @nonus_asian_sites ); -# $$page_content .= print_links( "South America", $file, @nonus_south_american_sites ); + if (!%data && $arch ne 'all' && $final_result->[3] eq 'all') { + %data = split /\000/, $packages_all{"$pkg all $final_result->[7]"}; + $arch = 'all'; + debug( "choosing arch 'all' instead of requested arch $arch", 1 ); +# fatal_error( _g( "No such package." )."
    ". +# sprintf( _g( 'Search for the package' ), "$SEARCH_URL/$pkg" ) ) unless %data; + } + @file_components = split('/', $data{filename}); + $filename = pop(@file_components); + $directory = join( '/', @file_components).'/'; + + $page_content->{archive} = $archive; + $page_content->{suite} = $suite; + $page_content->{pkg} = $pkg; + my $pkgsize = floor(($data{size}/102.4)+0.5)/10; + if ($pkgsize < 1024) { + $page_content->{pkgsize} = sprintf( '%.1f', $pkgsize ); + $page_content->{pkgsize_unit} = _g( 'kByte' ); + } else { + $page_content->{pkgsize} = sprintf( '%.1f', floor(($data{size}/(102.4*102.4))+0.5)/100 ); + $page_content->{pkgsize_unit} = _g( 'MByte' ); + } + $page_content->{architecture} = $arch; + foreach (keys %data) { + $page_content->{$_} = $data{$_}; + } + $page_content->{filename} = { file => $filename, + directory => $directory, + full => $data{filename}, + }; - $$page_content .= <If none of the above sites are fast enough for you, please see our - complete mirror list.

    -END -; - } elsif ($archive eq 'us') { - - $$page_content .= '
    '; - $$page_content .= print_links( "North America", $file, @north_american_sites ); - $$page_content .= '
    '; - $$page_content .= print_links( "Europe", $file, @european_sites ); - $$page_content .= '
    '; - $$page_content .= print_links( "Australia and New Zealand", $file, @australian_sites ); - $$page_content .= '
    '; - $$page_content .= print_links( "Asia", $file, @asian_sites ); - $$page_content .= '
    '; - $$page_content .= print_links( "South America", $file, @south_american_sites ); - $$page_content .= '
    '; - - $$page_content .= <If none of the above sites are fast enough for you, please see our - complete mirror list.

    -END -; } - - $$page_content .= <Note that in some browsers you will need to tell your browser you want - the file saved to a file. For example, in Netscape or Mozilla, you should - hold the Shift key when you click on the URL.

    -END -; - $$page_content .= "

    The MD5sum for $filen is $md5sum

    \n" - if $md5sum; } -} - -sub print_links { - my ( $title, $file, @servers ) = @_; - - my $str = "

    $title

    "; - $str .= "
      "; - foreach (@servers) { - $str .= "
    • $_
    • \n"; - # $str .= "
    • $_
    • \n"; - } - $str .= "
    "; - - return $str; + } 1;