Changeset 27371 for gs2-extensions/parallel-building
- Timestamp:
- 2013-05-21T13:35:48+12:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gs2-extensions/parallel-building/trunk/src/perllib/dbutil/gdbml.pm
r26933 r27371 1 1 ########################################################################### 2 2 # 3 # dbutil::gdbml -- utility functions for writing to gdbm databases4 # 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) 6 6 # 7 7 # A component of the Greenstone digital library software … … 9 9 # University of Waikato, New Zealand. 10 10 # 11 # Copyright (C) 20 0911 # Copyright (C) 2013 12 12 # 13 13 # This program is free software; you can redistribute it and/or modify … … 31 31 use strict; 32 32 33 use dbutil::gdbmtxtgz; 33 use dbutil::gdbm; 34 35 BEGIN 36 { 37 @dbutil::gdbml::ISA = ('dbutil::gdbm'); 38 } 34 39 35 40 # ----------------------------------------------------------------------------- … … 45 50 # also, we assume the path is correct to find the executable [jmt12] 46 51 my $txt2db_exe = "txt2dbl" . &util::get_os_exe(); 47 #my $txt2db_exe = "txt2db" . &util::get_os_exe();48 52 my $infodb_file_handle = undef; 49 53 my $cmd = "\"$txt2db_exe\""; … … 52 56 } 53 57 $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 # }61 58 62 59 if(!open($infodb_file_handle, "| $cmd")) … … 74 71 75 72 76 77 sub close_infodb_write_handle78 {79 my $infodb_handle = shift(@_);80 close($infodb_handle);81 }82 83 84 sub get_infodb_file_path85 {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 95 73 sub read_infodb_file 96 74 { … … 99 77 100 78 # 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"; 103 80 104 81 binmode(PIPEIN,":utf8"); … … 130 107 sub read_infodb_keys 131 108 { 132 my $infodb_file_path = shift(@_);133 my $infodb_map = shift(@_);134 135 109 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 line148 149 $infodb_map->{$infodb_line} = 1;150 }151 152 close (PIPEIN);153 110 } 154 155 sub write_infodb_entry156 {157 # With infodb_handle already set up, works the same as _gdbm_txtgz version158 &dbutil::gdbmtxtgz::write_infodb_entry(@_);159 }160 161 sub write_infodb_rawentry162 {163 # With infodb_handle already set up, works the same as _gdbm_txtgz version164 &dbutil::gdbmtxtgz::write_infodb_rawentry(@_);165 }166 167 168 sub set_infodb_entry_OLD169 {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 gdbmset175 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 etc180 $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 string193 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 GDBM199 my $cmd = "gdbmset \"$infodb_file_path\" \"$infodb_key\" \"$serialized_infodb_map\"";200 my $status = system($cmd);201 202 return $status;203 204 }205 206 207 111 208 112 sub set_infodb_entry … … 233 137 # Store it into GDBM using 'txt2db -append' which despite its name 234 138 # actually replaces the record if it already exists 235 236 139 # note the use of locking enabled txt2db [jmt12] 237 140 my $cmd = "txt2dbl -append \"$infodb_file_path\""; … … 257 160 } 258 161 259 260 sub delete_infodb_entry261 {262 # With infodb_handle already set up, works the same as _gdbm_txtgz version263 &dbutil::gdbmtxtgz::delete_infodb_entry(@_);264 }265 266 267 268 162 1;
Note:
See TracChangeset
for help on using the changeset viewer.