Changeset 30339


Ignore:
Timestamp:
2015-12-03T15:50:42+13:00 (8 years ago)
Author:
jmt12
Message:

Interim commit due to unexplained hardlock and subsequent 'failed command: READ FPDMA QUEUED' errors on restart

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs2-extensions/tdb/trunk/perllib/DBDrivers/GDBMTXTGZ.pm

    r30318 r30339  
    3232use util;
    3333use FileUtils;
    34 use DBDrivers::GDBM;
     34# - OO inheritence
     35use parent 'DBDrivers::GDBM';
    3536
    36 sub BEGIN
    37 {
    38     @DBDrivers::GDBMTXTGZ::ISA = ( 'DBDrivers::GDBM' );
    39 }
    4037
    4138sub new
    4239{
    4340    my $class = shift(@_);
    44     return bless ($self, $class);
     41    my $self = DBDrivers::GDBM->new();
     42    # Default TDB file extension
     43    $self->{'default_file_extension'} = 'txt.gz';
     44    # note: file separator agnostic
     45    $self->{'executable_path'} = $ENV{'GSDLHOME'} . '/bin/' . $ENV{'GSDLOS'};
     46    $self->{'read_executable'} = 'gzip --decompress --to-stdout';
     47    $self->{'keyread_executable'} = $self->{'read_executable'};
     48    $self->{'write_executable'} = 'gzip -';
     49    bless ($self, $class);
     50    return $self;
    4551}
    4652
     
    4955# -----------------------------------------------------------------------------
    5056
    51 # With infodb_handle already set up, these functions work the same as parent version
    52 # sub close_infodb_write_handle {}
    53 # sub delete_infodb_entry {}
    54 # sub write_infodb_entry {}
    55 # sub write_infodb_rawentry {}
     57# Handled by BaseDBDriver
     58# sub get_infodb_file_path(string, string)
     59
     60# Handled by 70HyphenFormat
     61# sub close_infodb_write_handle(filehandle) => void
     62# sub delete_infodb_entry(filehandle, string) => void
     63# sub read_infodb_file(string, hashmap) => void
     64# sub read_infodb_keys(string, hashmap) => void
     65# sub write_infodb_entry(filehandle, string, hashmap) => void
     66# sub write_infodb_rawentry(filehandle, string, string) => void
    5667
    5768
     
    6778# other
    6879#
     80# All this function does now is turn the optional 'append' argument into the
     81# appropriate operator for either appending to or clobbering gzip file.
     82#
    6983sub open_infodb_write_handle
    7084{
     85    my $self = shift(@_);
    7186    my $infodb_file_path = shift(@_);
    72 
    73     # Greenstone ships with gzip for windows, on $PATH
    74     my $infodb_file_handle = undef;
    75     if (!open($infodb_file_handle, "| gzip - > \"$infodb_file_path\"")) {
    76         print STDERR "Error: Failed to open pipe to gzip - > \"$infodb_file_path\"\n";
    77         print STDERR "       $!\n";
    78         return undef;
     87    my $opt_append = shift(@_);
     88    my $infodb_file_handle;
     89    if (defined $opt_append) {
     90    my $output_operator = '>'; # clobber
     91    if ($opt_append eq "append") {
     92        $output_operator = '>>'; # append
     93    }
     94    $infodb_file_handle = $self->open_infodb_write_handle($infodb_file_path, $output_operator);
    7995    }
    80     binmode($infodb_file_handle,":utf8");
     96    else {
     97    $infodb_file_handle = $self->open_infodb_write_handle($infodb_file_path);
     98    }
    8199    return $infodb_file_handle;
    82100}
    83101## open_infodb_write_handle(string) => filehandle ##
    84 
    85 
    86 ## @function get_infodb_file_path(string, string)
    87 #
    88 sub get_infodb_file_path
    89 {
    90     my $collection_name = shift(@_);
    91     my $infodb_directory_path = shift(@_);
    92 
    93     my $infodb_file_name = &util::get_dirsep_tail($collection_name).".txt.gz";
    94     return &util::filename_cat($infodb_directory_path, $infodb_file_name);
    95 }
    96 ## get_infodb_file_path(string, string) => string ##
    97 
    98 
    99 ## @function read_infodb_file(string, hashmap)
    100 #
    101 sub read_infodb_file
    102 {
    103     my $infodb_file_path = shift(@_);
    104     my $infodb_map = shift(@_);
    105 
    106     my $cmd = "gzip --decompress --to-stdout \"$infodb_file_path\"";
    107 
    108     open (PIPEIN, "$cmd |") || die "Error: Couldn't open pipe from gzip: $!\n  $cmd\n";
    109 
    110     binmode(PIPEIN,":utf8");
    111     my $infodb_line = "";
    112     my $infodb_key = "";
    113     my $infodb_value = "";
    114     while (defined ($infodb_line = <PIPEIN>)) {
    115         $infodb_line =~ s/(\r\n)+$//; # more general than chomp
    116 
    117         if ($infodb_line =~ /^\[([^\]]+)\]$/) {
    118             $infodb_key = $1;
    119         }
    120         elsif ($infodb_line =~ /^-{70}$/) {
    121             $infodb_map->{$infodb_key} = $infodb_value;
    122             $infodb_key = "";
    123             $infodb_value = "";
    124         }
    125         else {
    126             $infodb_value .= $infodb_line;
    127         }
    128     }
    129 
    130     close (PIPEIN);
    131 }
    132 ## read_infodb_file(string, hashmap) => void ##
    133 
    134 
    135 ## @function read_infodb_keys(string, hashmap)
    136 #
    137 sub read_infodb_keys
    138 {
    139     my $infodb_file_path = shift(@_);
    140     my $infodb_map = shift(@_);
    141 
    142     my $cmd = "gzip --decompress --to-stdout \"$infodb_file_path\"";
    143 
    144     open (PIPEIN, "$cmd |") || die "Error: Couldn't open pipe from gzip: $!\n  $cmd\n";
    145 
    146     binmode(PIPEIN,":utf8");
    147     my $infodb_line = "";
    148     my $infodb_key = "";
    149     while (defined ($infodb_line = <PIPEIN>)) {
    150         $infodb_line =~ s/(\r\n)+$//; # more general than chomp
    151 
    152         if ($infodb_line =~ /^\[([^\]]+)\]$/) {
    153             $infodb_key = $1;
    154         }
    155         elsif ($infodb_line =~ /^-{70}$/) {
    156             $infodb_map->{$infodb_key} = 1;
    157             $infodb_key = "";
    158         }
    159     }
    160 
    161     close (PIPEIN);
    162 }
    163 ## read_infodb_keys(string, hashmap) => void ##
    164102
    165103
     
    168106sub set_infodb_entry
    169107{
    170     my $infodb_file_path = shift(@_);
    171     my $infodb_key = shift(@_);
    172     my $infodb_map = shift(@_);
    173 
     108    my $self = shift(@_);
    174109    print STDERR "***** gdbmtxtgz::set_infodb_entry() not implemented yet!\n";
    175110}
Note: See TracChangeset for help on using the changeset viewer.