--- trunk2/lib/WebPAC.pm 2004/12/28 04:12:06 608 +++ trunk2/lib/WebPAC.pm 2004/12/31 02:19:24 609 @@ -150,7 +150,8 @@ =head2 open_isis -Open CDS/ISIS database using OpenIsis module and read all records to memory. +Open CDS/ISIS, WinISIS or IsisMarc database using IsisDB or OpenIsis module +and read all records to memory. $webpac->open_isis( filename => '/data/ISIS/ISIS', @@ -198,8 +199,6 @@ $self->{'isis_filename'} = $arg->{'filename'}; $self->{'isis_code_page'} = $code_page; - use OpenIsis; - #$self->{'isis_code_page'} = $code_page; # create Text::Iconv object @@ -208,9 +207,31 @@ $log->info("reading ISIS database '",$arg->{'filename'},"'"); $log->debug("isis code page: $code_page"); - my $isis_db = OpenIsis::open($arg->{'filename'}); + my $use_openisis = 1; + + eval { use IsisDB 0.06; }; + $use_openisis = 0 unless ($@); + + my ($isis_db,$maxmfn); + + if ($use_openisis) { + use OpenIsis; + $isis_db = OpenIsis::open($arg->{'filename'}); + $maxmfn = OpenIsis::maxRowid( $isis_db ) || 1; + } else { + $isis_db = new IsisDB( + isisdb => $arg->{'filename'}, + include_deleted => 1, + hash_filter => sub { + my $l = shift || return; + $l = $cp->convert($l); + return $l; + }, + ); + $maxmfn = $isis_db->{'maxmfn'}; + } + - my $maxmfn = OpenIsis::maxRowid( $isis_db ) || 1; my $startmfn = 1; if (my $s = $self->{'start_mfn'}) { @@ -222,7 +243,8 @@ $maxmfn = $startmfn + $self->{limit_mfn} if ($self->{limit_mfn}); - $log->info("processing ",($maxmfn-$startmfn)." records..."); + $log->info("processing ",($maxmfn-$startmfn)." records using ",( $use_openisis ? 'OpenIsis' : 'IsisDB')); + # read database for (my $mfn = $startmfn; $mfn <= $maxmfn; $mfn++) { @@ -232,29 +254,34 @@ my $rec; - # read record - my $row = OpenIsis::read( $isis_db, $mfn ); - foreach my $k (keys %{$row}) { - if ($k ne "mfn") { - foreach my $l (@{$row->{$k}}) { - $l = $cp->convert($l); - # has subfields? - my $val; - if ($l =~ m/\^/) { - foreach my $t (split(/\^/,$l)) { - next if (! $t); - $val->{substr($t,0,1)} = substr($t,1); + if ($use_openisis) { + + # read record using OpenIsis + my $row = OpenIsis::read( $isis_db, $mfn ); + foreach my $k (keys %{$row}) { + if ($k ne "mfn") { + foreach my $l (@{$row->{$k}}) { + $l = $cp->convert($l); + # has subfields? + my $val; + if ($l =~ m/\^/) { + foreach my $t (split(/\^/,$l)) { + next if (! $t); + $val->{substr($t,0,1)} = substr($t,1); + } + } else { + $val = $l; } - } else { - $val = $l; - } - push @{$rec->{$k}}, $val; + push @{$rec->{$k}}, $val; + } + } else { + push @{$rec->{'000'}}, $mfn; } - } else { - push @{$rec->{'000'}}, $mfn; } + } else { + $rec = $isis_db->to_hash($mfn); } $log->confess("record $mfn empty?") unless ($rec); @@ -364,17 +391,13 @@ # reset on re-run if ($p < $self->{'last_pcnt'}) { $self->{'last_pcnt'} = $p; - $self->{'last_t'} = time(); - $self->{'last_curr'} = undef; + $self->{'start_t'} = time(); } - $self->{'last_t'} ||= time(); - if ($p != $self->{'last_pcnt'}) { - my $last_curr = $self->{'last_curr'} || $curr; my $t = time(); - my $rate = ($curr - $last_curr) / (($t - $self->{'last_t'} || 1)); + my $rate = ($curr / ($t - $self->{'start_t'} || 1)); my $eta = ($max-$curr) / ($rate || 1); printf STDERR ("%5d [%-38s] %-5d %0.1f/s %s\r",$curr,"=" x ($p/3)."$p%>", $max, $rate, $self->fmt_time($eta)); $self->{'last_pcnt'} = $p;