Ignore:
Timestamp:
2008-08-14T16:42:19+12:00 (16 years ago)
Author:
davidb
Message:

Improvement to downloading capabilities for WGet and OAI

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/perllib/downloaders/WgetDownload.pm

    r14918 r16791  
    105105    my $strOptions = "";
    106106   
    107     if($self->{'proxy_on'} && $self->{'proxy_host'} && $self->{'proxy_port'})
     107    if ($self->{'proxy_on'} && $self->{'proxy_host'} && $self->{'proxy_port'})
    108108    {
    109109
     
    116116    }
    117117
    118     $strOptions .= " -Y on ";
     118    if ($self->{'proxy_on'}) {
     119    $strOptions .= " --proxy ";
     120    }
    119121
    120122    return $strOptions;
     
    167169}
    168170
     171
     172sub useWgetMonitored
     173{
     174    my ($self, $cmdWget,$blnShow, $working_dir) = @_;
     175
     176
     177    my $current_dir = cwd();
     178    my $changed_dir = 0;
     179    if (defined $working_dir && -e $working_dir) {
     180    chdir "$working_dir";
     181    $changed_dir = 1;
     182    }
     183    my $wget_file_path = &util::filename_cat($ENV{'GSDLHOME'}, "bin", $ENV{'GSDLOS'}, "wget");
     184    my $command = "\"$wget_file_path\" $cmdWget 2>&1 |";
     185
     186###    print STDERR "**** wget cmd = $command\n";
     187
     188    open(*WIN,$command) || die "wget request failed: $!\n";
     189
     190    my $full_text = "";
     191    my $error_text = "";
     192    my @follow_list = ();
     193    my $line;
     194
     195    while (defined($line=<WIN>))
     196    {
     197    if((defined $blnShow) && $blnShow)
     198    {
     199        print STDERR "$line";
     200    }
     201
     202    if ($line =~ m/^Location:\s*(.*?)\s*\[following\]\s*$/i) {
     203        my $follow_url = $1;
     204        push(@follow_list,$follow_url);
     205    }
     206
     207    if ($line =~ m/ERROR\s+\d+/) {
     208        $error_text .= $line;
     209    }
     210
     211    $full_text .= $line;
     212    }
     213
     214    close(WIN);
     215
     216    my $command_status = $?;
     217    if ($command_status != 0) {
     218    $error_text .= "Exit error: $command_status";
     219    }
     220
     221    if ($changed_dir) {
     222    chdir $current_dir;
     223    }
     224   
     225    my $final_follow = pop(@follow_list); # might be undefined, but that's OK
     226   
     227    return ($full_text,$error_text,$final_follow);
     228}
     229
     230
    169231# TODO: Check if the URL is valid?? Not sure what should be in this function yet!!
    170232sub checkURL
Note: See TracChangeset for help on using the changeset viewer.