diff options
author | Francois Pons <fpons@mandriva.com> | 2003-01-22 21:29:55 +0000 |
---|---|---|
committer | Francois Pons <fpons@mandriva.com> | 2003-01-22 21:29:55 +0000 |
commit | 805250fd0ee514af20171de3f06773c4a162327d (patch) | |
tree | 0cb41f1e1b0dd69f7902c2711f4da44ca202fb6f | |
parent | 1fc5d0ad0160a5985b7d70c77e2edcecbe11700f (diff) | |
download | urpmi-805250fd0ee514af20171de3f06773c4a162327d.tar urpmi-805250fd0ee514af20171de3f06773c4a162327d.tar.gz urpmi-805250fd0ee514af20171de3f06773c4a162327d.tar.bz2 urpmi-805250fd0ee514af20171de3f06773c4a162327d.tar.xz urpmi-805250fd0ee514af20171de3f06773c4a162327d.zip |
4.2-8mdk
-rw-r--r-- | urpm.pm | 78 | ||||
-rwxr-xr-x | urpmi | 14 | ||||
-rw-r--r-- | urpmi.spec | 5 |
3 files changed, 80 insertions, 17 deletions
@@ -222,15 +222,41 @@ sub sync_webfetch { } sub sync_wget { -x "/usr/bin/wget" or die _("wget is missing\n"); + local *WGET; my $options = shift @_; - system "/usr/bin/wget", - (ref $options && set_proxy({type => "wget", proxy => $options->{proxy}})), - (ref $options && $options->{quiet} ? ("-q") : ("-nv")), "--retr-symlinks", "-NP", - (ref $options ? $options->{dir} : $options), @_; - $? == 0 or die _("wget failed: exited with %d or signal %d\n", $? >> 8, $? & 127); + my ($buf, $file) = ('', undef); + open WGET, "-|", "/usr/bin/wget", + (ref $options && set_proxy({type => "wget", proxy => $options->{proxy}})), + (ref $options && $options->{callback} ? ("--progress=bar:force", "-o", "-") : + ref $options && $options->{quiet} ? ("-q") : ("")), + "--retr-symlinks", "-NP", + (ref $options ? $options->{dir} : $options), @_; + local $/ = \1; #- read input by only one char, this is slow but very nice (and it works!). + while (<WGET>) { + $buf .= $_; + if ($_ eq "\r" || $_ eq "\n") { + if (ref $options && $options->{callback}) { + if ($buf =~ /^--\d\d:\d\d:\d\d--\s+(\S.*)\n/ms) { + $file = $1; + $options->{callback}('start', $file); + } elsif (my ($percent, $eta, $speed) = $buf =~ /^\s*(\d+)%\s+.*\s+(\S+)\s+ETA\s+(\S+)[\r\n]$/ms) { + $options->{callback}('progress', $file, $percent, undef, $eta, $speed); + if ($_ eq "\n") { + $options->{callback}('end', $file); + $file = undef; + } + } + } else { + print STDERR $_; + } + $buf = ''; + } + } + close WGET or die _("wget failed: exited with %d or signal %d\n", $? >> 8, $? & 127); } sub sync_curl { -x "/usr/bin/curl" or die _("curl is missing\n"); + local *CURL; my $options = shift @_; chdir (ref $options ? $options->{dir} : $options); my (@ftp_files, @other_files); @@ -244,11 +270,9 @@ sub sync_curl { require Date::Manip; #- prepare to get back size and time stamp of each file. - local *CURL; open CURL, "/usr/bin/curl" . " " . (ref $options && set_proxy({type => "curl", proxy => $options->{proxy}})) . - " " . (ref $options && $options->{quiet} ? ("-s") : ()) . - " -I " . join(" ", map { "'$_'" } @ftp_files) . " |"; + " -s -I " . join(" ", map { "'$_'" } @ftp_files) . " |"; while (<CURL>) { if (/Content-Length:\s*(\d+)/) { !$cur_ftp_file || exists $ftp_files_info{$cur_ftp_file}{size} and $cur_ftp_file = shift @ftp_files; @@ -283,11 +307,35 @@ sub sync_curl { #- options for ftp files, -R (-O <file>)* #- options for http files, -R (-z file -O <file>)* if (my @all_files = ((map { ("-O", $_ ) } @ftp_files), (map { /\/([^\/]*)$/ ? ("-z", $1, "-O", $_) : () } @other_files))) { - system "/usr/bin/curl", - (ref $options && set_proxy({type => "curl", proxy => $options->{proxy}})), - (ref $options && $options->{quiet} ? ("-s") : ()), "-R", "-f", - @all_files; - $? == 0 or die _("curl failed: exited with %d or signal %d\n", $? >> 8, $? & 127); + my @l = (@ftp_files, @other_files); + my ($buf, $file) = ('', undef); + open CURL, "-|", "/usr/bin/curl", + (ref $options && set_proxy({type => "curl", proxy => $options->{proxy}})), + (ref $options && $options->{quiet} && !$options->{verbose} ? ("-s") : ()), "-R", "-f", "--stderr", "-", + @all_files; + local $/ = \1; #- read input by only one char, this is slow but very nice (and it works!). + while (<CURL>) { + $buf .= $_; + if ($_ eq "\r" || $_ eq "\n") { + if (ref $options && $options->{callback}) { + unless (defined $file) { + $file = shift @l; + $options->{callback}('start', $file); + } + if (my ($percent, $total, $eta, $speed) = $buf =~ /^\s*(\d+)\s+(\S+)[^\r\n]*\s+(\S+)\s+(\S+)[\r\n]$/ms) { + $options->{callback}('progress', $file, $percent, $total, $eta, $speed); + if ($_ eq "\n") { + $options->{callback}('end', $file); + $file = undef; + } + } + } else { + print STDERR $_; + } + $buf = ''; + } + } + close CURL or die _("curl failed: exited with %d or signal %d\n", $? >> 8, $? & 127); } } sub sync_rsync { @@ -2121,12 +2169,10 @@ sub download_source_packages { if (%distant_sources) { eval { $urpm->{log}(_("retrieving rpm files from medium \"%s\"...", $urpm->{media}[$_]{name})); - foreach (map { m|([^:]*://[^/:\@]*:)[^/:\@]*(\@.*)| ? "$1xxxx$2" : $_ } values %distant_sources) { - $urpm->{log}(" $_") ; - } $urpm->{sync}({ dir => "$urpm->{cachedir}/rpms", quiet => 0, verbose => $options{verbose}, + callback => $options{callback}, proxy => $urpm->{proxy}}, values %distant_sources); $urpm->{log}(_("...retrieving done")); @@ -257,6 +257,7 @@ if ($log) { open SAVEOUT, ">&STDOUT"; select SAVEOUT; $| = 1; open SAVEERR, ">&STDERR"; select SAVEERR; $| = 1; unless ($pid_out = open STDOUT, "|-") { + my $buf_r; while (<STDIN>) { open F, ">>$log"; select F; $| = 1; select SAVEOUT; $| = 1; @@ -268,6 +269,7 @@ if ($log) { exit 0; } unless ($pid_err = open STDERR, "|-") { + my $buf_r; while (<STDIN>) { open F, ">>$log"; select F; $| = 1; select SAVEERR; $| = 1; @@ -482,6 +484,18 @@ unless ($local_sources || $list) { my %sources = $urpm->download_source_packages($local_sources, $list, verbose => $verbose > 0, + callback => sub { + my ($mode, $file, $percent, $total, $eta, $speed) = @_; + if ($mode eq 'start') { + $file =~ s|([^:]*://[^/:\@]*:)[^/:\@]*(\@.*)|$1xxxx$2|; #- if needed... + print SAVEERR " $file\n"; + } elsif ($mode eq 'progress') { + print SAVEERR _(" %s%% of %s, ETA = %s, speed = %s", + $percent, $total, $eta, $speed) . "\r"; + } elsif ($mode eq 'end') { + print SAVEERR (" "x79)."\r"; + } + }, force_local => !$X, ask_for_medium => (!$auto || $allow_medium_change) && sub { my $msg = _("Please insert the medium named \"%s\" on device [%s]", @_); my $msg2 = _("Press Enter when ready..."); @@ -2,7 +2,7 @@ Name: urpmi Version: 4.2 -Release: 7mdk +Release: 8mdk License: GPL Source0: %{name}.tar.bz2 Source1: %{name}.logrotate @@ -205,6 +205,9 @@ fi %changelog +* Wed Jan 22 2003 François Pons <fpons@mandrakesoft.com> 4.2-8mdk +- add callback support for download (fix bug 632 and 387). + * Mon Jan 20 2003 François Pons <fpons@mandrakesoft.com> 4.2-7mdk - fixed bug 876. |