summaryrefslogtreecommitdiff
path: root/Master
diff options
context:
space:
mode:
authorNorbert Preining <preining@logic.at>2009-12-16 07:06:01 +0000
committerNorbert Preining <preining@logic.at>2009-12-16 07:06:01 +0000
commit7a3ba3138290c49da244552d62e88a08b2d14e78 (patch)
treeed48216d1a7539d48f0eb44ca9f2bd08fbd0f51c /Master
parent1501e3ba218f0698b94682df440b76ff94d64606 (diff)
implement --persistent-downloads using LWP
git-svn-id: svn://tug.org/texlive/trunk@16424 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master')
-rwxr-xr-xMaster/install-tl13
-rwxr-xr-xMaster/texmf/scripts/texlive/tlmgr.pl18
-rw-r--r--Master/tlpkg/TeXLive/TLDownload.pm131
-rw-r--r--Master/tlpkg/TeXLive/TLUtils.pm23
4 files changed, 182 insertions, 3 deletions
diff --git a/Master/install-tl b/Master/install-tl
index c37f1c72008..a66a755d9c7 100755
--- a/Master/install-tl
+++ b/Master/install-tl
@@ -57,6 +57,7 @@ use TeXLive::TLUtils qw(platform platform_desc
use TeXLive::TLPOBJ;
use TeXLive::TLPDB;
use TeXLive::TLConfig;
+use TeXLive::TLDownload;
if (win32) {
require TeXLive::TLWinGoo;
@@ -159,6 +160,7 @@ my $opt_scheme = "";
my $opt_custom_bin;
my $opt_version = 0;
my $opt_force_arch;
+my $opt_persistent_downloads = 0;
# show all options even those not relevant for that arch
$::opt_all_options = 0;
@@ -212,6 +214,7 @@ GetOptions(
"profile=s" => \$opt_profile,
"scheme=s" => \$opt_scheme,
"all-options" => \$::opt_all_options,
+ "persistent-downloads" => \$opt_persistent_downloads,
"version" => \$opt_version,
"help|?" => \$opt_help) or pod2usage(1);
@@ -415,6 +418,7 @@ if ($media eq "DVD") {
} elsif ($media eq "NET") {
info("Distribution: net (downloading)\n");
info("Using URL: $TeXLiveURL\n");
+ TeXLive::TLUtils::setup_persistent_downloads() if $opt_persistent_downloads;
} else {
info("Distribution: $media\n");
}
@@ -1846,6 +1850,15 @@ will be adjusted accordingly.
For backward compatibility and convenience, C<--location> and C<--repo>
are accepted as aliases for this option.
+=item B<-persistent-downloads>
+
+Try to set up a persistent connection using Net::LWP if
+you are installing from the network. This will keep the connection
+between your computer and the server open for the whole session and
+reuse this connection.
+
+This option should reduce the probability to have connection problems.
+
=item B<-no-cls>
(only for text mode installer) do not clear the screen when entering
diff --git a/Master/texmf/scripts/texlive/tlmgr.pl b/Master/texmf/scripts/texlive/tlmgr.pl
index 94ce675604a..7a12456bfda 100755
--- a/Master/texmf/scripts/texlive/tlmgr.pl
+++ b/Master/texmf/scripts/texlive/tlmgr.pl
@@ -82,6 +82,7 @@ use TeXLive::TLPDB;
use TeXLive::TLPOBJ;
use TeXLive::TLUtils;
use TeXLive::TLWinGoo;
+use TeXLive::TLDownload;
TeXLive::TLUtils->import(qw(member info give_ctan_mirror win32 dirname
mkdirhier copy log debug tlcmp));
use TeXLive::TLPaper;
@@ -124,6 +125,7 @@ sub main {
"location|repository|repo" => "=s",
"machine-readable" => 1,
"package-logfiles" => "=s",
+ "persistent-downloads" => 1,
"pause" => 1,
"version" => 1,
"help|h|?" => 1);
@@ -320,7 +322,14 @@ sub main {
$loadmediasrcerror = "Cannot load TeX Live database from ";
+ #
+ # if we are asked to use persistent connections try to start it here
+ #
+ TeXLive::TLUtils::setup_persistent_downloads()
+ if $opts{'persistent-downloads'};
+
execute_action($action, @ARGV);
+
# end of main program.
} # end main
@@ -4234,6 +4243,15 @@ L<option> action).
For backward compatibility and convenience, C<--location> and C<--repo>
are accepted as aliases for this option.
+=item B<-persistent-downloads>
+
+Try to set up a persistent connection using Net::LWP if
+you are installing from the network. This will keep the connection
+between your computer and the server open for the whole session and
+reuse this connection.
+
+This option should reduce the probability to have connection problems.
+
=item B<--gui> [I<action>]
You can give this option together with an action to be brought directly
diff --git a/Master/tlpkg/TeXLive/TLDownload.pm b/Master/tlpkg/TeXLive/TLDownload.pm
new file mode 100644
index 00000000000..55ea323d0f3
--- /dev/null
+++ b/Master/tlpkg/TeXLive/TLDownload.pm
@@ -0,0 +1,131 @@
+# $Id$
+# TeXLive::TLDownload.pm - module for abstracting the download modes
+# Copyright 2009 Norbert Preining
+#
+# This file is licensed under the GNU General Public License version 2
+# or any later version.
+#
+
+
+package TeXLive::TLDownload;
+
+use TeXLive::TLUtils;
+use File::Temp qw/tempfile/;
+
+my $svnrev = '$Revision$';
+my $_modulerevision;
+if ($svnrev =~ m/: ([0-9]+) /) {
+ $_modulerevision = $1;
+} else {
+ $_modulerevision = "unknown";
+}
+sub module_revision {
+ return $_modulerevision;
+}
+
+
+# since Net::HTTP and Net::FTP are shipped by the same packages
+# we only test for Net::HTTP, if that fails, let us know ;-)
+our $net_lib_avail = 0;
+eval { require LWP; };
+if ($@) {
+ debug("LWP is not available, falling back to wget mode.\n");
+ $net_lib_avail = 0;
+} else {
+ require LWP::UserAgent;
+ require HTTP::Status;
+ $net_lib_avail = 1;
+ debug("LWP available!\n");
+}
+
+
+sub new
+{
+ my $class = shift;
+ my $self = {};
+ my $ua = LWP::UserAgent->new(
+ agent => "texlive/lwp",
+ keep_alive => 3,
+ env_proxy => 1,
+ );
+ $self->{'ua'} = $ua;
+ bless $self, $class;
+ return $self;
+}
+
+
+
+sub get_file
+{
+ my ($self, $url, $out, $size) = @_;
+ #
+ my $realout = $out;
+ my ($outfh, $outfn);
+ if ($out eq "|") {
+ ($outfh, $outfn) = tempfile();
+ $realout = $outfn;
+ }
+ my $response = $self->{'ua'}->get($url, ':content_file' => $realout);
+ if ($response->is_success) {
+ if ($out ne "|") {
+ return 1;
+ } else {
+ # seek to beginning of file
+ seek $outfh, 0, 0;
+ return $outfh;
+ }
+ } else {
+ tlwarn("TLDownload::get_file: response error:\n");
+ tlwarn(" " . $response->status_line . "\n");
+ return;
+ }
+}
+
+
+
+1;
+__END__
+
+
+=head1 NAME
+
+C<TeXLive::TLDownload> -- TeX Live Download abstraction module
+
+=head1 SYNOPSIS
+
+ use TeXLive::TLDownload;
+
+ $TeXLive::TLDownload::net_lib_avail
+ my $dl = TeXLive::TLDownload->new();
+ $dl->get_file($relpath, $output [, $expected_size ]);
+
+=head1 DESCRIPTION
+
+The C<TeXLive::TLDownload> is a simple wrapper around the LWP modules
+that allows for persistent connections and different protocols.
+At loading time it checks for the existence of the LWP module(s),
+and sets C<$TeXLive::TLDownload::net_lib_avail> accordingly.
+
+=head2 Using proxies
+
+Please see C<LWP::UserAgent> for details, in a nut shell one can
+specify proxies by setting C<I<protocol>_proxy> variable.
+
+=head1 SEE ALSO
+
+LWP
+
+=head1 AUTHORS AND COPYRIGHT
+
+This script and its documentation were written for the TeX Live
+distribution (L<http://tug.org/texlive>) and both are licensed under the
+GNU General Public License Version 2 or later.
+
+=cut
+
+### Local Variables:
+### perl-indent-level: 2
+### tab-width: 2
+### indent-tabs-mode: nil
+### End:
+# vim:set tabstop=2 expandtab: #
diff --git a/Master/tlpkg/TeXLive/TLUtils.pm b/Master/tlpkg/TeXLive/TLUtils.pm
index 0812af55609..6dc3022ece9 100644
--- a/Master/tlpkg/TeXLive/TLUtils.pm
+++ b/Master/tlpkg/TeXLive/TLUtils.pm
@@ -79,6 +79,7 @@ C<TeXLive::TLUtils> -- utilities used in the TeX Live infrastructure
TeXLive::TLUtils::remove_symlinks($root, $arch, $sys_bin, $sys_man, $sys_info);
TeXLive::TLUtils::w32_add_to_path($bindir, $multiuser);
TeXLive::TLUtils::w32_remove_from_path($bindir, $multiuser);
+ TeXLive::TLUtils::setup_persistent_downloads();
=head2 Miscellaneous
@@ -156,6 +157,7 @@ BEGIN {
&compare_tlpobjs
&compare_tlpdbs
&report_tlpdb_differences
+ &setup_persistent_downloads
);
@EXPORT = qw(setup_programs download_file process_logging_options
tldie tlwarn info log debug ddebug dddebug debug_hash
@@ -168,6 +170,7 @@ use Getopt::Long;
use File::Temp;
use TeXLive::TLConfig;
+
$::opt_verbosity = 0; # see process_logging_options
@@ -2226,10 +2229,10 @@ sub download_file {
} else {
$url = "$TeXLiveURL/$relpath";
}
- if (defined($::current_server)) {
- if ($::current_server->get_file($url, $dest)) {
+ if (defined($::tldownload_server)) {
+ if (($ret = $::tldownload_server->get_file($url, $dest))) {
debug("downloading file via permanent connection succeeded\n");
- return 1;
+ return $ret;
} else {
tlwarn("permanent server connection set up, but downloading did not succeed!");
tlwarn("Retrying with wget.\n");
@@ -2993,6 +2996,20 @@ sub conv_to_w32_path {
return($p);
}
+=item C<setup_persistent_downloads()>
+
+Setup the system to use persistent connections using LWP/TLDownload.
+
+=cut
+
+sub setup_persistent_downloads
+{
+ if (!$TeXLive::TLDownload::net_lib_avail) {
+ tlwarn("Cannot set up persistent connections, LWP is missing.\n");
+ return 0;
+ }
+ return ($::tldownload_server = TeXLive::TLDownload->new);
+}
=item C<give_ctan_mirror()>