Changeset 17230 for gsdl/trunk/perllib/downloaders/SRWDownload.pm
- Timestamp:
- 2008-09-09T19:15:00+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/perllib/downloaders/SRWDownload.pm
r17219 r17230 78 78 my ($strOpen,$strBase,$strFind,$strResponse,$intAmount,$intMaxRecords,$strRecords); 79 79 80 # If the url contains just the host and port (as it would for Z39.50), then prepend 81 # the http protocol. Otherwise the download is stuck in an infinite loop for SRW/SRU 82 $self->{'url'} = "http://$self->{'url'}" if $self->{'url'} !~ m/^http/; 80 83 my $url = $self->{'url'}; 81 84 82 85 print STDERR "<<Defined Maximum>>\n"; 83 86 84 my $yaz = $self->{'yaz'}; 85 86 my $childpid = open2(*YAZOUT, *YAZIN, $yaz) 87 or (print STDERR "<<Finished>>\n" and die "can't open pipe to yaz-client: $!"); 88 89 $self->{'YAZOUT'} = *YAZOUT; 90 $self->{'YAZIN'} = *YAZIN; 91 92 $strOpen = $self->open_connection("open $url"); 93 94 if (!$strOpen) { 95 print STDERR "Cannot connect to $url\n"; 96 print STDERR "<<Finished>>\n"; 97 return 0; 98 } 99 87 $strOpen = $self->start_yaz($url); 88 100 89 print STDERR "Opening connection to \"$self->{'url'}\"\n"; 101 90 print STDERR "Access database: \"$self->{'database'}\"\n"; … … 103 92 $self->run_command_without_output("querytype prefix"); 104 93 print STDERR "Searching for keyword: \"$self->{'find'}\"\n"; 94 105 95 $intAmount =$self->findAmount($self->{'find'}); 106 96 … … 109 99 ($intAmount == -1)? 110 100 print STDERR "Something wrong with the arguments,downloading can not be performed\n" : 111 112 101 print STDERR "No Record is found\n"; 102 print STDERR "<<Finished>>\n"; 113 103 return 0; 114 104 } 115 105 $intMaxRecords = ($self->{'max_records'} > $intAmount)? $intAmount : $self->{'max_records'}; 116 106 print STDERR "<<Total number of record(s):$intMaxRecords>>\n"; 117 107 118 108 $strRecords = $self->getRecords($intMaxRecords); 119 109 120 110 $self->saveRecords($strRecords,$hashGeneralOptions->{'cache_dir'},$intMaxRecords); 121 111 print STDERR "Closing connection...\n"; 122 print STDERR "<<Finished>>\n"; 123 124 # need to send the quit command, else yaz-client is still running in the background 125 $self->run_command_without_output("quit"); 126 close(YAZOUT); 127 close(YAZIN); 112 113 $self->quit_yaz(); 128 114 return 1; 129 115 } … … 148 134 &util::mk_all_dir($strSubDirPath); 149 135 150 print STDERR "Saving records to \"$strOutputFile\"\n";136 print STDERR "Saving records to \"$strOutputFile\"\n"; 151 137 152 138 # save record … … 157 143 } 158 144 159 sub get {145 sub get { 160 146 my ($self,$strShow,$numRecord) = @_; 161 147 162 $self->run_command ($strShow);163 148 $self->run_command_without_output($strShow); 149 164 150 my $strFullOutput=""; 165 151 my $count=0; 166 152 my $readRecord = 0; 167 168 while (my $strLine = <YAZOUT>) 153 my $endRecord = 0; 154 155 my $output = $self->{'YAZOUT'}; 156 my $strLine; 157 158 while ($strLine = <$output>) #while (defined ($strLine = <$output>)) 169 159 { 170 171 return $strFullOutput if ($count >= $numRecord); 172 173 return $strFullOutput if($strLine =~ m/^HTTP ERROR/i); 174 175 if ($strLine =~ m/pos=[\d]*/i ){ 160 last if ($count >= $numRecord && $endRecord); # done, if we've reached the end of the last record 161 162 last if($strLine =~ m/^HTTP ERROR/i); 163 164 if ($strLine =~ m/pos=[\d]*/i ) { 176 165 $count++; 177 166 $readRecord = 1; 178 next; 167 $endRecord = 0; 168 next; 179 169 } 180 170 171 if ($strLine =~ m/<\/record>/i ) { # end tag of record 172 $endRecord = 1; 173 } 174 181 175 next if(!$readRecord); 182 176 183 177 $strFullOutput .= $strLine; 184 178 } 185 179 180 return $strFullOutput; 186 181 } 187 182
Note:
See TracChangeset
for help on using the changeset viewer.