/[BackupPC]/trunk/lib/BackupPC/SearchLib.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/BackupPC/SearchLib.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 225 by dpavlin, Mon Oct 24 14:02:00 2005 UTC revision 303 by dpavlin, Sat Jan 28 16:45:46 2006 UTC
# Line 17  my $pager_pages = 10; Line 17  my $pager_pages = 10;
17  my $dsn = $Conf{SearchDSN};  my $dsn = $Conf{SearchDSN};
18  my $db_user = $Conf{SearchUser} || '';  my $db_user = $Conf{SearchUser} || '';
19    
20  my $hest_index_path = $Conf{HyperEstraierIndex};  my $hest_node_url = $Conf{HyperEstraierIndex};
21    
22  my $dbh;  my $dbh;
23    
# Line 251  sub getHyperEstraier_url($) { Line 251  sub getHyperEstraier_url($) {
251    
252          return unless $use_hest;          return unless $use_hest;
253    
254          use HyperEstraier;          use Search::Estraier;
255          my ($index_path, $index_node_url);          die "direct access to Hyper Estraier datatase is no longer supported. Please use estmaster\n"
256                    unless ($use_hest =~ m#^http://#);
257    
258          if ($use_hest =~ m#^http://#) {          return $use_hest;
                 $index_node_url = $use_hest;  
         } else {  
                 $index_path = $TopDir . '/' . $index_path;  
                 $index_path =~ s#//#/#g;  
         }  
         return ($index_path, $index_node_url);  
259  }  }
260    
261  sub getFilesHyperEstraier($) {  sub getFilesHyperEstraier($) {
# Line 269  sub getFilesHyperEstraier($) { Line 264  sub getFilesHyperEstraier($) {
264          my $offset = $param->{'offset'} || 0;          my $offset = $param->{'offset'} || 0;
265          $offset *= $on_page;          $offset *= $on_page;
266    
267          die "no index_path?" unless ($hest_index_path);          die "no Hyper Estraier node URL?" unless ($hest_node_url);
   
         use HyperEstraier;  
   
         my ($index_path, $index_node_url) = getHyperEstraier_url($hest_index_path);  
268    
269          # open the database          # open the database
270          my $db;          my $db;
271          if ($index_path) {          if ($hest_node_url) {
272                  $db = HyperEstraier::Database->new();                  $db ||= Search::Estraier::Node->new($hest_node_url);
                 $db->open($index_path, $HyperEstraier::ESTDBREADER);  
         } elsif ($index_node_url) {  
                 $db ||= HyperEstraier::Node->new($index_node_url);  
273                  $db->set_auth('admin', 'admin');                  $db->set_auth('admin', 'admin');
274          } else {          } else {
275                  die "BUG: unimplemented";                  die "BUG: unimplemented";
276          }          }
277    
278          # create a search condition object          # create a search condition object
279          my $cond = HyperEstraier::Condition->new();          my $cond = Search::Estraier::Condition->new();
280    
281          my $q = $param->{'search_filename'};          my $q = $param->{'search_filename'};
282          my $shareid = $param->{'search_share'};          my $shareid = $param->{'search_share'};
# Line 313  sub getFilesHyperEstraier($) { Line 301  sub getFilesHyperEstraier($) {
301          $cond->add_attr("shareid NUMEQ $shareid") if ($shareid);          $cond->add_attr("shareid NUMEQ $shareid") if ($shareid);
302    
303  #       $cond->set_max( $offset + $on_page );  #       $cond->set_max( $offset + $on_page );
304          $cond->set_options( $HyperEstraier::Condition::SURE );          $cond->set_options( SURE => 1 );
305          $cond->set_order( getSort('search', 'est', $param->{'sort'} ) );          $cond->set_order( getSort('search', 'est', $param->{'sort'} ) );
306    
307          # get the result of search          # get the result of search
308          my @res;          my @res;
309          my ($result, $hits);          my ($result, $hits);
310    
311          if ($index_path) {          if ($hest_node_url) {
                 $result = $db->search($cond, 0);  
                 $hits = $result->size;  
         } elsif ($index_node_url) {  
312                  $result = $db->search($cond, 0);                  $result = $db->search($cond, 0);
313                  $hits = $result->doc_num;                  if ($result) {
314                            $hits = $result->doc_num;
315                    } else {
316                            $hits = 0;
317                    }
318          } else {          } else {
319                  die "BUG: unimplemented";                  die "BUG: unimplemented";
320          }          }
# Line 335  sub getFilesHyperEstraier($) { Line 324  sub getFilesHyperEstraier($) {
324                  last if ($i >= $hits);                  last if ($i >= $hits);
325    
326                  my $doc;                  my $doc;
327                  if ($index_path) {                  if ($hest_node_url) {
                         my $id = $result->get($i);  
                         $doc = $db->get_doc($id, 0);  
                 } elsif ($index_node_url) {  
328                          $doc = $result->get_doc($i);                          $doc = $result->get_doc($i);
329                  } else {                  } else {
330                          die "BUG: unimplemented";                          die "BUG: unimplemented";
# Line 377  sub get_tgz_size_by_name($) { Line 363  sub get_tgz_size_by_name($) {
363    
364          my $size = -1;          my $size = -1;
365    
366          if (-f $tgz) {          if (-f "${tgz}.tar.gz") {
367                  $size = (stat($tgz))[7];                  $size = (stat("${tgz}.tar.gz"))[7];
368          } elsif (-d $tgz) {          } elsif (-d $tgz) {
369                  opendir(my $dir, $tgz) || die "can't opendir $tgz: $!";                  opendir(my $dir, $tgz) || die "can't opendir $tgz: $!";
370                  my @parts = grep { !/^\./ && -f "$tgz/$_" } readdir($dir);                  my @parts = grep { !/^\./ && !/md5/ && -f "$tgz/$_" } readdir($dir);
371                  $size = 0;                  $size = 0;
372                  foreach my $part (@parts) {                  foreach my $part (@parts) {
373                          $size += (stat("$tgz/$part"))[7] || die "can't stat $tgz/$part: $!";                          $size += (stat("$tgz/$part"))[7] || die "can't stat $tgz/$part: $!";
374                  }                  }
375                  closedir $dir;                  closedir $dir;
376            } else {
377                    return -1;
378          }          }
379    
380          return $size;          return $size;
# Line 418  sub getGzipSize($$) Line 406  sub getGzipSize($$)
406          );          );
407  }  }
408    
409    sub getVolumes($) {
410            my $id = shift;
411    
412            my $max_archive_size = $Conf{MaxArchiveSize} || die "no MaxArchiveSize";
413    
414            my $sth = $dbh->prepare(qq{
415                    select
416                            size
417                    from backup_parts
418                    where backup_id = ?
419                    order by part_nr asc
420            });
421    
422            $sth->execute($id);
423    
424            my $cumulative_size = 0;
425            my $volumes = 1;
426    
427            while(my ($size) = $sth->fetchrow_array) {
428                    if ($cumulative_size + $size > $max_archive_size) {
429                            $volumes++;
430                            $cumulative_size = $size;
431                    } else {
432                            $cumulative_size += $size;
433                    }
434            }
435    
436            return ($volumes,$cumulative_size);
437    }
438    
439  sub getBackupsNotBurned($) {  sub getBackupsNotBurned($) {
440    
441          my $param = shift;          my $param = shift;
# Line 466  print STDERR "## sort=". ($param->{'sort Line 484  print STDERR "## sort=". ($param->{'sort
484          while ( my $row = $sth->fetchrow_hashref() ) {          while ( my $row = $sth->fetchrow_hashref() ) {
485                  $row->{'age'} = sprintf("%0.1f", ( $row->{'age'} / 86400 ) );                  $row->{'age'} = sprintf("%0.1f", ( $row->{'age'} / 86400 ) );
486                  #$row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) );                  #$row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) );
                 $row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024);  
487    
488                  # do some cluster calculation (approximate) and convert to kB                  my $max_archive_size = $Conf{MaxArchiveSize} || die "no MaxArchiveSize";
489                  $row->{'inc_size'} = int(($row->{'inc_size'} + 1023 ) / ( 2 * 1024 ) * 2);                  if ($row->{size} > $max_archive_size) {
490                            ($row->{volumes}, $row->{inc_size_calc}) = getVolumes($row->{id});
491                    }
492    
493                    $row->{size} = sprintf("%0.2f", $row->{size} / 1024 / 1024);
494    
495                    # do some cluster calculation (approximate)
496                    $row->{inc_size} = int(( ($row->{inc_size} + 1023 ) / 2 )  * 2);
497                    $row->{inc_size_calc} ||= $row->{inc_size};
498                  push @ret, $row;                  push @ret, $row;
499          }          }
500                
501          return @ret;                return @ret;
502  }  }
503    
504  sub displayBackupsGrid($) {  sub displayBackupsGrid($) {
505    
506          my $param = shift;          my $param = shift;
507    
508            my $max_archive_size = $Conf{MaxArchiveSize} || die "no MaxArchiveSize";
509            my $max_archive_file_size = $Conf{MaxArchiveFileSize}  || die "no MaxFileInSize";
510    
511          my $retHTML .= q{          my $retHTML .= q{
512                  <form id="forma" method="POST" action="}.$MyURL.q{?action=burn">                  <form id="forma" method="POST" action="}.$MyURL.q{?action=burn">
513          };          };
# Line 586  DIV#fixedBox #submitBurner { Line 614  DIV#fixedBox #submitBurner {
614          background-color: transparent;          background-color: transparent;
615  }  }
616    
617  #parts {  #volumes {
618          padding: 0.4em;          padding: 0.4em;
619          display: none;          display: none;
620          width: 100%;          width: 100%;
# Line 603  var debug_div = null; Line 631  var debug_div = null;
631  EOF3  EOF3
632    
633          # take maximum archive size from configuration          # take maximum archive size from configuration
634          $retHTML .= 'var media_size = '. $Conf{MaxArchiveSize} .';';          $retHTML .= qq{
635    var media_size = $max_archive_size ;
636    var max_file_size = $max_archive_file_size;
637    
638    };
639    
640          $retHTML .= <<'EOF3';          $retHTML .= <<'EOF3';
641    
642  function debug(msg) {  function debug(msg) {
643          return; // Disable debugging  //      return; // Disable debugging
644    
645          if (! debug_div) debug_div = document.getElementById('debug');          if (! debug_div) debug_div = document.getElementById('debug');
646    
# Line 666  function checkAll(location) { Line 698  function checkAll(location) {
698    
699  function update_sum(suma, suma_disp) {  function update_sum(suma, suma_disp) {
700          if (! suma_disp) suma_disp = suma;          if (! suma_disp) suma_disp = suma;
701          element_id('forma').elements['totalsize'].value = suma_disp;          suma_disp = Math.floor(suma_disp / 1024);
702            element_id('forma').elements['totalsize_kb'].value = suma_disp;
703            element_id('forma').elements['totalsize'].value = suma;
704          pbar_set(suma, media_size);          pbar_set(suma, media_size);
705          debug('total size: ' + suma);          debug('total size: ' + suma);
706  }  }
707    
708  function sumiraj(e) {  function update_size(name, checked, suma) {
709          var suma = parseInt(element_id('forma').elements['totalsize'].value) || 0;          var size = parseInt( element_id("fss" + name).value);
710          var len = element_id('forma').elements.length;  
711          if (e) {          if (checked) {
712                  var size = parseInt( element_id("fss" + e.name.substr(3)).value);                  suma += size;
713                  if (e.checked) {          } else {
714                          suma += size;                  suma -= size;
715            }
716    
717            var volumes = parseInt( element_id("prt" + name).value);
718            debug('update_size('+name+','+checked+') suma: '+suma+' volumes: '+volumes);
719            if (volumes > 1) {
720                    if (checked) {
721                            element_id("volumes").innerHTML = "This will take "+volumes+" mediums!";
722                            element_id("volumes").style.display = 'block';
723                            suma = size;
724                            update_sum(suma);
725                  } else {                  } else {
726                          suma -= size;                          suma -= size;
727                            element_id("volumes").style.display = 'none';
728                  }                  }
729            }
730    
731                  var parts = parseInt( element_id("prt" + e.name.substr(3)).value);          return suma;
732                  if (suma > media_size && suma == size && parts > 1) {  }
                         element_id("parts").innerHTML = "This will take "+parts+" mediums!";  
                         element_id("parts").style.display = 'block';  
                         update_sum(media_size, suma);  
                         suma = media_size;  
                         return suma;  
                 } else {  
                         element_id("parts").style.display = 'none';  
                 }  
733    
734    function sumiraj(e) {
735            var suma = parseInt(element_id('forma').elements['totalsize'].value) || 0;
736            var len = element_id('forma').elements.length;
737            if (e) {
738                    suma = update_size(e.name.substr(3), e.checked, suma);
739                  if (suma < 0) suma = 0;                  if (suma < 0) suma = 0;
740          } else {          } else {
741                  suma = 0;                  suma = 0;
742                  for (var i = 0; i < len; i++) {                  for (var i = 0; i < len; i++) {
743                          var e = element_id('forma').elements[i];                          var fel = element_id('forma').elements[i];
744                          if (e.name != 'all' && e.checked && e.name.substr(0,3) == 'fcb') {                          if (fel.name != 'all' && fel.checked && fel.name.substr(0,3) == 'fcb') {
745                                  var el = element_id("fss" + e.name.substr(3));                                  suma = update_size(fel.name.substr(3), fel.checked, suma);
                                 if (el && el.value) suma += parseInt(el.value) || 0;  
746                          }                          }
747                  }                  }
748          }          }
# Line 782  self.onload = self.document.onload = sel Line 824  self.onload = self.document.onload = sel
824  </script>  </script>
825  <div id="fixedBox">  <div id="fixedBox">
826    
827  Size: <input type="text" name="totalsize" size="7" readonly="readonly" style="text-align:right;" value="0" /> kB  <input type="hidden" name="totalsize"/>
828    Size: <input type="text" name="totalsize_kb" size="7" readonly="readonly" style="text-align:right;" value="0" /> kB
829    
830  <div id="mContainer">  <div id="mContainer">
831          <div id="gradient">&nbsp;</div>          <div id="gradient">&nbsp;</div>
# Line 791  Size: <input type="text" name="totalsize Line 834  Size: <input type="text" name="totalsize
834  </div>  </div>
835  <br/>  <br/>
836    
837  <div id="parts">&nbsp;</div>  <div id="volumes">&nbsp;</div>
838    
839  Note:  Note:
840  <textarea name="note" cols="10" rows="5" id="note"></textarea>  <textarea name="note" cols="10" rows="5" id="note"></textarea>
# Line 824  EOF3 Line 867  EOF3
867                  sort_header($param, 'Size/Mb', 'size', 'center') .                  sort_header($param, 'Size/Mb', 'size', 'center') .
868                  sort_header($param, 'gzip size/Kb', 'incsize', 'center') .                  sort_header($param, 'gzip size/Kb', 'incsize', 'center') .
869          qq{          qq{
870                          </tr>                          <td align="center">medias</td></tr>
871          };          };
872    
873          my @color = (' bgcolor="#e0e0e0"', '');          my @color = (' bgcolor="#e0e0e0"', '');
# Line 851  EOF3 Line 894  EOF3
894                          <input type="checkbox" name="fcb' . $checkbox_key . '" value="' . $checkbox_key . '" onClick="sumiraj(this);">';                          <input type="checkbox" name="fcb' . $checkbox_key . '" value="' . $checkbox_key . '" onClick="sumiraj(this);">';
895                  }                  }
896    
897                    my $img_url = $Conf{CgiImageDirURL};
898    
899                  $retHTML .=                  $retHTML .=
900                          '</td>' .                          '</td>' .
901                          '<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' .                          '<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' .
# Line 859  EOF3 Line 904  EOF3
904                          '<td align="center">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .                          '<td align="center">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .
905                          '<td align="center">' . $backup->{'age'} . '</td>' .                          '<td align="center">' . $backup->{'age'} . '</td>' .
906                          '<td align="right">' . $backup->{'size'} . '</td>' .                          '<td align="right">' . $backup->{'size'} . '</td>' .
907                          '<td align="right">' . $backup->{'inc_size'} .                          '<td align="right">' . sprintf("%0.1f", $backup->{'inc_size'} / 1024 ) .
908                          '<input type="hidden" id="fss'.$checkbox_key .'" value="'. $backup->{'inc_size'} .'"></td>' .                          '<input type="hidden" id="fss'.$checkbox_key .'" value="'. $backup->{'inc_size_calc'} .'"></td>' .
909                          '<input type="hidden" id="prt'.$checkbox_key .'" value="'. $backup->{'parts'} .'"></td>' .                          '<input type="hidden" id="prt'.$checkbox_key .'" value="'. $backup->{'volumes'} .'"></td>' .
910                            '<td align="left">' . ( qq{<img src="$img_url/icon-cd.gif" alt="media">} x $backup->{volumes} ) . '</td>' .
911    
912                          "</tr>\n";                          "</tr>\n";
913          }          }
# Line 918  sub displayGrid($) { Line 964  sub displayGrid($) {
964          sub sort_header($$$$) {          sub sort_header($$$$) {
965                  my ($param, $display, $name, $align) = @_;                  my ($param, $display, $name, $align) = @_;
966    
967                  my ($sort_what, $sort_dir) = split(/_/,$param->{'sort'},2);                  my ($sort_what, $sort_direction) = split(/_/,$param->{'sort'},2);
968    
969                  my $old_sort = $param->{'sort'};                  my $old_sort = $param->{'sort'};
970    
971                  my $html = qq{<td align="$align"};                  my $html = qq{<td align="$align"};
972                    my $arrow = '';
973    
974                  if (lc($sort_what) eq lc($name)) {                  if (lc($sort_what) eq lc($name)) {
975                          my $dir = lc($sort_dir);                          my $direction = lc($sort_direction);
976                          $dir =~ tr/ad/da/;  
977                          $param->{'sort'} = $name . '_' . $dir;                          # swap direction or fallback to default
978                            $direction =~ tr/ad/da/;
979                            $direction = 'a' unless ($direction =~ /[ad]/);
980    
981                            $param->{'sort'} = $name . '_' . $direction;
982                          $html .= ' style="border: 1px solid #808080;"';                          $html .= ' style="border: 1px solid #808080;"';
983                    
984                            # add unicode arrow for direction
985                            $arrow .= '&nbsp;';
986                            $arrow .= $direction eq 'a'  ?  '&#9650;'
987                                    : $direction eq 'd'  ?  '&#9660;'
988                                    :                       ''
989                                    ;
990    
991                  } else {                  } else {
992                          $param->{'sort'} = $name . '_a';                          $param->{'sort'} = $name . '_a';
993                  }                  }
994                  $html .= '<a href="' . page_uri($param) . '">' . $display . '</a></td>';  
995                    $html .= '><a href="' . page_uri($param) . '">' . $display . '</a>' . $arrow . '</td>';
996                  $param->{'sort'} = $old_sort;                  $param->{'sort'} = $old_sort;
997    
998                  return $html;                  return $html;

Legend:
Removed from v.225  
changed lines
  Added in v.303

  ViewVC Help
Powered by ViewVC 1.1.26