1 | ###############################################################################
|
---|
2 | #
|
---|
3 | # GDBMTXTGZ.pm -- utility functions for writing to gdbm-txtgz databases
|
---|
4 | #
|
---|
5 | # A component of the Greenstone digital library software from the New Zealand
|
---|
6 | # Digital Library Project at the University of Waikato, New Zealand.
|
---|
7 | #
|
---|
8 | # Copyright (c) 2015 New Zealand Digital Library Project
|
---|
9 | #
|
---|
10 | # This program is free software; you can redistribute it and/or modify it under
|
---|
11 | # the terms of the GNU General Public License as published by the Free Software
|
---|
12 | # Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | # version.
|
---|
14 | #
|
---|
15 | # This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
---|
17 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
---|
18 | # more details.
|
---|
19 | #
|
---|
20 | # You should have received a copy of the GNU General Public License along with
|
---|
21 | # this program; if not, write to the Free Software Foundation, Inc., 675 Mass
|
---|
22 | # Ave, Cambridge, MA 02139, USA.
|
---|
23 | #
|
---|
24 | ###############################################################################
|
---|
25 |
|
---|
26 | package DBDrivers::GDBMTXTGZ;
|
---|
27 |
|
---|
28 | # Pragma
|
---|
29 | use strict;
|
---|
30 |
|
---|
31 | # Libraries
|
---|
32 | use util;
|
---|
33 | use FileUtils;
|
---|
34 | use DBDrivers::70HyphenFormat;
|
---|
35 |
|
---|
36 | BEGIN
|
---|
37 | {
|
---|
38 | @DBDrivers::GDBMTXTGZ::ISA = ('DBDrivers::70HyphenFormat');
|
---|
39 | }
|
---|
40 |
|
---|
41 |
|
---|
42 | ## Constructor
|
---|
43 | sub new
|
---|
44 | {
|
---|
45 | my $class = shift(@_);
|
---|
46 | my $self = DBDrivers::70HyphenFormat->new(@_);
|
---|
47 | # Default TDB file extension
|
---|
48 | $self->{'default_file_extension'} = 'txt.gz';
|
---|
49 | # note: file separator agnostic
|
---|
50 | $self->{'executable_path'} = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'}, 'bin', $ENV{'GSDLOS'});
|
---|
51 | $self->{'read_executable'} = 'gzip --decompress --to-stdout';
|
---|
52 | $self->{'keyread_executable'} = $self->{'read_executable'};
|
---|
53 | $self->{'write_executable'} = 'gzip -';
|
---|
54 | bless ($self, $class);
|
---|
55 | return $self;
|
---|
56 | }
|
---|
57 |
|
---|
58 | # -----------------------------------------------------------------------------
|
---|
59 | # GDBM TXT-GZ IMPLEMENTATION
|
---|
60 | # -----------------------------------------------------------------------------
|
---|
61 |
|
---|
62 | # Handled by BaseDBDriver
|
---|
63 | # sub get_infodb_file_path(string, string)
|
---|
64 |
|
---|
65 | # Handled by 70HyphenFormat
|
---|
66 | # sub close_infodb_write_handle(filehandle) => void
|
---|
67 | # sub read_infodb_file(string, hashmap) => void
|
---|
68 | # sub read_infodb_keys(string, hashmap) => void
|
---|
69 | # sub write_infodb_entry(filehandle, string, hashmap) => void
|
---|
70 | # sub write_infodb_rawentry(filehandle, string, string) => void
|
---|
71 |
|
---|
72 |
|
---|
73 | ## @function open_infodb_write_handle(string)
|
---|
74 | #
|
---|
75 | # Keep infodb in GDBM neutral form => save data as compressed text file, read
|
---|
76 | # for txt2db to be run on it later (i.e. by the runtime system, first time the
|
---|
77 | # collection is ever accessed). This makes it easier distribute pre-built
|
---|
78 | # collections to various architectures.
|
---|
79 | #
|
---|
80 | # NB: even if two architectures are little endian (e.g. Intel and ARM procesors)
|
---|
81 | # GDBM does *not* guarantee that the database generated on one will work on the
|
---|
82 | # other
|
---|
83 | #
|
---|
84 | # Now only responsible for transforming the optional append argument into the
|
---|
85 | # correct redirection operand (either > for clobber or >> for append)
|
---|
86 | #
|
---|
87 | sub open_infodb_write_handle
|
---|
88 | {
|
---|
89 | my $self = shift(@_);
|
---|
90 | my $infodb_file_path = shift(@_);
|
---|
91 | my $opt_append = shift(@_);
|
---|
92 | my $infodb_file_handle;
|
---|
93 | # append
|
---|
94 | if (defined $opt_append && $opt_append =~ /^-?append$/) {
|
---|
95 | $infodb_file_handle = $self->SUPER::open_infodb_write_handle($infodb_file_path, '>>');
|
---|
96 | }
|
---|
97 | # create or clobber
|
---|
98 | else {
|
---|
99 | $infodb_file_handle = $self->SUPER::open_infodb_write_handle($infodb_file_path, '>');
|
---|
100 | }
|
---|
101 | return $infodb_file_handle;
|
---|
102 | }
|
---|
103 | ## open_infodb_write_handle(string) => filehandle ##
|
---|
104 |
|
---|
105 | ## @function set_infodb_entry(string, string, hashmap)
|
---|
106 | #
|
---|
107 | sub set_infodb_entry
|
---|
108 | {
|
---|
109 | my $self = shift(@_);
|
---|
110 | print STDERR "***** gdbmtxtgz::set_infodb_entry() not implemented yet!\n";
|
---|
111 | }
|
---|
112 | ## set_infodb_entry(string, string, hashmap) => void ##
|
---|
113 |
|
---|
114 |
|
---|
115 | 1;
|
---|