Ignore:
Timestamp:
2013-05-21T13:35:48+12:00 (11 years ago)
Author:
jmt12
Message:

Replacing with a proper class inheriting from gdbm and just overriding the two calls to the executable

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs2-extensions/parallel-building/trunk/src/perllib/dbutil/gdbml.pm

    r26933 r27371  
    11###########################################################################
    22#
    3 # dbutil::gdbml -- utility functions for writing to gdbm databases
    4 #
    5 # Adding file locking to allow for multiple readers/writers (albeit slow)
     3# dbutil::gdbml -- extends the dbutil::gdbm class by adding simple file
     4# locking so as to allow for multiple readers/writers (albeit slow and not
     5# supported over network filesystems)
    66#
    77# A component of the Greenstone digital library software
     
    99# University of Waikato, New Zealand.
    1010#
    11 # Copyright (C) 2009
     11# Copyright (C) 2013
    1212#
    1313# This program is free software; you can redistribute it and/or modify
     
    3131use strict;
    3232
    33 use dbutil::gdbmtxtgz;
     33use dbutil::gdbm;
     34
     35BEGIN
     36{
     37  @dbutil::gdbml::ISA = ('dbutil::gdbm');
     38}
    3439
    3540# -----------------------------------------------------------------------------
     
    4550  # also, we assume the path is correct to find the executable [jmt12]
    4651  my $txt2db_exe = "txt2dbl" . &util::get_os_exe();
    47   #my $txt2db_exe = "txt2db" . &util::get_os_exe();
    4852  my $infodb_file_handle = undef;
    4953  my $cmd = "\"$txt2db_exe\"";
     
    5256  }
    5357  $cmd .= " \"$infodb_file_path\"";
    54 
    55   # Why? Why do you hate me? [jmt12]
    56 #  if (!-e "$txt2db_exe")
    57 #  {
    58 #      print STDERR "Error: Unable to find $txt2db_exe\n";
    59 #      return undef;
    60 #  }
    6158
    6259  if(!open($infodb_file_handle, "| $cmd"))
     
    7471
    7572
    76 
    77 sub close_infodb_write_handle
    78 {
    79   my $infodb_handle = shift(@_);
    80   close($infodb_handle);
    81 }
    82 
    83 
    84 sub get_infodb_file_path
    85 {
    86   my $collection_name = shift(@_);
    87   my $infodb_directory_path = shift(@_);
    88 
    89   my $infodb_file_extension = ".gdb";
    90   my $infodb_file_name = &util::get_dirsep_tail($collection_name) . $infodb_file_extension;
    91   return &util::filename_cat($infodb_directory_path, $infodb_file_name);
    92 }
    93 
    94 
    9573sub read_infodb_file
    9674{
     
    9977
    10078  # note the use of locking enabled db2txt [jmt12]
    101   open (PIPEIN, "db2txtl \"$infodb_file_path\" |")
    102       || die "couldn't open pipe from db2txt \$infodb_file_path\"\n";
     79  open (PIPEIN, "db2txtl \"$infodb_file_path\" |") || die "couldn't open pipe from db2txt \$infodb_file_path\"\n";
    10380
    10481  binmode(PIPEIN,":utf8");
     
    130107sub read_infodb_keys
    131108{
    132   my $infodb_file_path = shift(@_);
    133   my $infodb_map = shift(@_);
    134 
    135109  die("[gdbmkeys] not implemented for parallel building");
    136 
    137   open (PIPEIN, "gdbmkeys \"$infodb_file_path\" |")
    138       || die "couldn't open pipe from gdbmkeys \$infodb_file_path\"\n";
    139 
    140   binmode(PIPEIN,":utf8");
    141 
    142   my $infodb_line = "";
    143   my $infodb_key = "";
    144   my $infodb_value = "";
    145   while (defined ($infodb_line = <PIPEIN>))
    146   {
    147       chomp $infodb_line; # remove end of line
    148 
    149       $infodb_map->{$infodb_line} = 1;
    150   }
    151 
    152   close (PIPEIN);
    153110}
    154 
    155 sub write_infodb_entry
    156 {
    157   # With infodb_handle already set up, works the same as _gdbm_txtgz version
    158   &dbutil::gdbmtxtgz::write_infodb_entry(@_);
    159 }
    160 
    161 sub write_infodb_rawentry
    162 {
    163   # With infodb_handle already set up, works the same as _gdbm_txtgz version
    164   &dbutil::gdbmtxtgz::write_infodb_rawentry(@_);
    165 }
    166 
    167 
    168 sub set_infodb_entry_OLD
    169 {
    170     my $infodb_file_path = shift(@_);
    171     my $infodb_key = shift(@_);
    172     my $infodb_map = shift(@_);
    173  
    174     # Protect metadata values that go inside quotes for gdbmset
    175     foreach my $k (keys %$infodb_map) {
    176       my @escaped_v = ();
    177       foreach my $v (@{$infodb_map->{$k}}) {
    178         if ($k eq "contains") {
    179           # protect quotes in ".2;".3 etc
    180           $v =~ s/\"/\\\"/g;
    181           push(@escaped_v, $v);
    182         }
    183         else {
    184           my $ev = &ghtml::unescape_html($v);
    185           $ev =~ s/\"/\\\"/g;
    186           push(@escaped_v, $ev);
    187         }
    188       }
    189       $infodb_map->{$k} = \@escaped_v;
    190     }
    191    
    192     # Generate the record string
    193     my $serialized_infodb_map = &dbutil::convert_infodb_hash_to_string($infodb_map);
    194 ##    print STDERR "**** ser dr\n$serialized_infodb_map\n\n\n";
    195 
    196     die("[gdbmset] not implemented for parallel building");
    197 
    198     # Store it into GDBM
    199     my $cmd = "gdbmset \"$infodb_file_path\" \"$infodb_key\" \"$serialized_infodb_map\"";
    200     my $status = system($cmd);
    201 
    202     return $status;
    203  
    204 }
    205 
    206 
    207111
    208112sub set_infodb_entry
     
    233137    # Store it into GDBM using 'txt2db -append' which despite its name
    234138    # actually replaces the record if it already exists
    235 
    236139    # note the use of locking enabled txt2db [jmt12]
    237140    my $cmd = "txt2dbl -append \"$infodb_file_path\"";
     
    257160}
    258161
    259 
    260 sub delete_infodb_entry
    261 {
    262   # With infodb_handle already set up, works the same as _gdbm_txtgz version
    263   &dbutil::gdbmtxtgz::delete_infodb_entry(@_);
    264 }
    265 
    266 
    267 
    2681621;
Note: See TracChangeset for help on using the changeset viewer.