source: main/trunk/greenstone2/perllib/colcfg.pm@ 27306

Last change on this file since 27306 was 27306, checked in by jmt12, 8 years ago

Moving the critical file-related functions (copy, rm, etc) out of util.pm into their own proper class FileUtils. Use of the old functions in util.pm will prompt deprecated warning messages. There may be further functions that could be moved across in the future, but these are the critical ones when considering supporting other filesystems (HTTP, HDFS, WebDav, etc). Updated some key files to use the new functions so now deprecated messages thrown when importing/building demo collection 'out of the box'

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 11.5 KB
Line 
1###########################################################################
2#
3# colcfg.pm --
4# A component of the Greenstone digital library software
5# from the New Zealand Digital Library Project at the
6# University of Waikato, New Zealand.
7#
8# Copyright (C) 1999 New Zealand Digital Library Project
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23#
24###########################################################################
25
26# reads/writes the collection configuration files:
27# collect.cfg/collectionConfig.xml and build.cfg/buildConfig.xml
28
29package colcfg;
30
31use cfgread;
32use gsprintf 'gsprintf';
33use util;
34use FileUtils;
35
36use strict;
37
38# the collection configuration file data is stored in the form
39#
40# {'infodbtype'}->string
41# {'creator'}->string
42# {'public'}->string
43# {'complexmeta'}->string (true, false)
44# {'defaultindex'}->string
45# {'importdir'}->string
46# {'archivedir'}->string
47# {'cachedir'}->string
48# {'builddir'}->string
49# {'removeold'}->string
50# {'textcompress'}->string
51# {'buildtype'}->string
52# {'orthogonalbuildtypes'}->array of strings
53# {'maxnumeric'}->string
54# {'separate_cjk'}->string
55# {'sections_index_document_metadata'}->string (always, unless_section_metadata_exists)
56# {'languagemetadata'} -> string
57# {'maintainer'}->array of strings
58# {'languages'}->array of strings
59# {'indexsubcollections'}->array of strings
60# {'indexes'}->array of strings
61# {'indexoptions'}->array of strings (stem, casefold, accentfold, separate_cjk)
62# {'dontbuild'}->array of strings
63# {'dontgdbm'}->array of strings
64# {'mirror'}->array of strings
65# {'phind'}->array of strings
66# {'plugout'}->array of strings
67# {'levels'}->array of strings (for mgpp eg Section, Paragraph)
68# {'searchtype'}->array of strings (for mgpp, form or plain)
69
70# {'subcollection'}->hash of key-value pairs
71
72# {'acquire'}->array of arrays of strings
73# {'plugin'}->array of arrays of strings
74# {'classify'}->array of arrays of strings
75
76# {'collectionmeta'}->hash of key->hash of param-value -used
77# for language specification
78# for example, collectionmeta->collectionname->default->demo
79# ->mi->maori demo
80
81# convenience method for reading in either collect.cfg/collectionConfig.xml
82sub read_collection_cfg {
83 my ($filename,$gs_mode) = @_;
84
85 my $collectcfg = undef;
86
87 if ($gs_mode eq "gs2") {
88 $collectcfg = &colcfg::read_collect_cfg ($filename);
89 } elsif ($gs_mode eq "gs3") {
90 $collectcfg = &colcfg::read_collection_cfg_xml ($filename);
91 }
92 else {
93 print STDERR "Failed to read collection configuration file\n";
94 print STDERR " Unrecognized mode: $gs_mode\n";
95 }
96
97 return $collectcfg;
98}
99
100# convenience method for writing out either collect.cfg/collectionConfig.xml
101# is this ever used??
102sub write_collection_cfg {
103 my ($filename, $collectcfg_data, $gs_mode) = @_;
104
105 if ($gs_mode eq "gs2") {
106 &colcfg::write_collect_cfg ($filename, $collectcfg_data );
107 } elsif ($gs_mode eq "gs3") {
108 &colcfg::write_collection_cfg_xml ($filename, $collectcfg_data);
109 }
110 else {
111 print STDERR "Failed to write collection configuration file\n";
112 print STDERR " Unrecognized mode: $gs_mode\n";
113 }
114}
115
116# the build configuration file data is stored in the form
117#
118# {'infodbtype'}->string
119# {'builddate'}->string
120# {'buildtype'}->string
121# {'orthogonalbuildtypes'}->array of strings
122# {'metadata'}->array of strings
123# {'languages'}->array of strings
124# {'numdocs'}->string
125# {'numsections'}->string
126# {'numwords'}->string
127# {'numbytes'}->string
128# {'maxnumeric'}->string
129# {'indexfields'}->array of strings
130# {'indexfieldmap'}->array of strings in the form "field->FI"
131# {'indexmap'} -> array of strings
132# {'indexlevels'} -> array of strings
133# {'stemindexes'} -> string (int)
134# {'textlevel'}->string
135# {'levelmap'} -> array of strings in the form "level->shortname"
136
137# convenience method for reading in either build.cfg/buildConfig.xml
138sub read_building_cfg {
139 my ($filename,$gs_mode) = @_;
140
141 my $buildcfg = undef;
142
143 if ($gs_mode eq "gs2") {
144 $buildcfg = &colcfg::read_build_cfg ($filename);
145 } elsif ($gs_mode eq "gs3") {
146 $buildcfg = &colcfg::read_build_cfg_xml ($filename);
147 }
148 else {
149 print STDERR "Failed to read building configuration file\n";
150 print STDERR " Unrecognized mode: $gs_mode\n";
151 }
152
153 return $buildcfg;
154}
155
156# convenience method for writing out either build.cfg/buildConfig.xml
157# haven't got one, as gs3 version needs extra parameters
158#sub write_building_cfg {}
159
160##############################
161### gs2/gs3 specific methods
162###############################
163
164#####################################
165### collect.cfg/collectionConfig.xml
166#####################################
167
168# gs2 read in collect.cfg
169sub read_collect_cfg {
170 my ($filename) = @_;
171
172 return &cfgread::read_cfg_file_unicode ($filename,
173 q/^(infodbtype|creator|public|complexmeta|defaultindex|importdir|/ .
174 q/archivedir|cachedir|builddir|removeold|/ .
175 q/textcompress|buildtype|othogonalbuildtypes|no_text|keepold|gzip|/ .
176 q/verbosity|remove_empty_classifications|OIDtype|OIDmetadata|/ .
177 q/groupsize|maxdocs|debug|mode|saveas|/ .
178 q/sortmeta|removesuffix|removeprefix|create_images|/ .
179 q/maxnumeric|languagemetadata|/ .
180 q/no_strip_html|index|sections_index_document_metadata|/ .
181 q/store_metadata_coverage|indexname|indexlevel)$/,
182 q/(maintainer|languages|indexsubcollections|orthogonalbuildtypes|/ .
183 q/indexes|indexoptions|dontbuild|dontgdbm|mirror|levels|plugout|/ .
184 q/searchtype|searchtypes)$/,
185 q/^(subcollection|format)$/,
186 q/^(acquire|plugin|classify)$/,
187 q/^(collectionmeta)$/);
188}
189
190# gs2 write out collect.cfg
191sub write_collect_cfg {
192 my ($filename, $data) = @_;
193
194 &cfgread::write_cfg_file($filename, $data,
195 q/^(infodbtype|creator|public|complexmeta|defaultindex|importdir|/ .
196 q/archivedir|cachedir|builddir|removeold|/ .
197 q/textcompress|buildtype|no_text|keepold|gzip|/ .
198 q/verbosity|remove_empty_classifications|OIDtype|OIDmetadata|/.
199 q/groupsize|maxdocs|debug|mode|saveas|/ .
200 q/sortmeta|removesuffix|removeprefix|create_images|/ .
201 q/maxnumeric|languagemetadata/ .
202 q/no_strip_html|index|sections_index_document_metadata)$/.
203 q/store_metadata_coverage)$/,
204 q/^(maintainer|languages|indexsubcollections|orthogonalbuildtypes|/ .
205 q/indexes|indexoptions|dontbuild|dontgdbm|mirror|levels|/.
206 q/searchtype|searchtypes)$/,
207 q/^(subcollection|format)$/,
208 q/^(acquire|plugin|classify)$/,
209 q/^(collectionmeta)$/);
210}
211
212# gs3 read in collectionConfig.xml
213sub read_collection_cfg_xml {
214 my ($filename) = @_;
215
216 require collConfigxml;
217 return &collConfigxml::read_cfg_file ($filename);
218}
219
220# gs3 write out collectionConfig.xml
221sub write_collection_cfg_xml {
222
223}
224
225#####################################
226### build.cfg/buildConfig.xml
227######################################
228
229# gs2 read build.cfg
230sub read_build_cfg {
231 my ($filename) = @_;
232
233 return &cfgread::read_cfg_file ($filename,
234 q/^(earliestdatestamp|infodbtype|builddate|buildtype|numdocs|numsections|numwords|numbytes|maxnumeric|textlevel|indexstem|stemindexes|separate_cjk)$/,
235 q/^(indexmap|subcollectionmap|languagemap|orthogonalbuildtypes|notbuilt|indexfields|indexfieldmap|indexlevels|levelmap)$/);
236
237}
238
239# gs2 write build.cfg
240sub write_build_cfg {
241 my ($filename, $data) = @_;
242
243 &cfgread::write_cfg_file($filename, $data,
244 q/^(earliestdatestamp|infodbtype|builddate|buildtype|numdocs|numsections|numwords|numbytes|maxnumeric|textlevel|indexstem|stemindexes|separate_cjk)$/,
245 q/^(indexmap|subcollectionmap|languagemap|orthogonalbuildtypes|notbuilt|indexfields|indexfieldmap|indexlevels|levelmap)$/);
246}
247
248# gs3 read buildConfig.xml
249sub read_build_cfg_xml {
250
251 my ($filename) = @_;
252
253 require buildConfigxml;
254 return &buildConfigxml::read_cfg_file($filename);
255}
256
257# gs3 write buildConfig.xml
258sub write_build_cfg_xml {
259 my ($buildoutfile, $buildcfg, $collectcfg) = @_;
260
261 require buildConfigxml;
262 return &buildConfigxml::write_cfg_file ($buildoutfile, $buildcfg, $collectcfg);
263}
264
265
266# method to check for filename of collect.cfg, and gs mode.
267sub get_collect_cfg_name_old {
268 my ($out) = @_;
269
270 # First check if there's a
271 # gsdl/collect/COLLECTION/custom/COLLECTION/etc/custom.cfg file. This
272 # customization was added for DLC by Stefan, 30/6/2007.
273 my $configfilename = &FileUtils::filenameConcatenate ($ENV{'GSDLCOLLECTDIR'}, "custom", $ENV{'GSDLCOLLECTION'}, "etc", "custom.cfg");
274
275 if (-e $configfilename) {
276 return ($configfilename, "gs2");
277 }
278
279 # Check if there is a collectionConfig.xml file. If there is one, it's gs3
280 $configfilename = &FileUtils::filenameConcatenate ($ENV{'GSDLCOLLECTDIR'}, "etc", "collectionConfig.xml");
281 if (-e $configfilename) {
282 return ($configfilename, "gs3");
283 }
284
285 # If we get to here we check if there is a collect.cfg file in the usual place, i.e. it is gs2.
286 $configfilename = &FileUtils::filenameConcatenate ($ENV{'GSDLCOLLECTDIR'}, "etc", "collect.cfg");
287 if (-e $configfilename) {
288 return ($configfilename, "gs2");
289 }
290
291 # Error. No collection configuration file.
292 (&gsprintf($out, "{common.cannot_find_cfg_file}\n", $configfilename) && die);
293}
294
295# method to check for filename of collect.cfg
296# needs to be given gs_version, since we can have a GS2 collection ported into
297# GS3 which could potentially have collect.cfg AND collectionConfig.xml
298# in which case the older version of this subroutine (get_collect_cfg_name_old)
299# will return the wrong answer for the gs version we're using.
300sub get_collect_cfg_name {
301 my ($out, $gs_version) = @_;
302
303 # First check if there's a
304 # gsdl/collect/COLLECTION/custom/COLLECTION/etc/custom.cfg file. This
305 # customization was added for DLC by Stefan, 30/6/2007.
306 my $configfilename;
307
308 if($gs_version eq "gs2") {
309 $configfilename = &FileUtils::filenameConcatenate ($ENV{'GSDLCOLLECTDIR'}, "custom", $ENV{'GSDLCOLLECTION'}, "etc", "custom.cfg");
310
311 if (-e $configfilename) {
312 return $configfilename;
313 }
314 }
315
316 # Check if there is a collectionConfig.xml file if it's gs3
317 if($gs_version eq "gs3") {
318 $configfilename = &FileUtils::filenameConcatenate ($ENV{'GSDLCOLLECTDIR'}, "etc", "collectionConfig.xml");
319 if (-e $configfilename) {
320 return $configfilename;
321 }
322 }
323
324 # Check if there is a collect.cfg file in the usual place for gs2.
325 if($gs_version eq "gs2") {
326 $configfilename = &FileUtils::filenameConcatenate ($ENV{'GSDLCOLLECTDIR'}, "etc", "collect.cfg");
327 if (-e $configfilename) {
328 return $configfilename;
329 }
330 }
331
332 # Error. No collection configuration file.
333 (&gsprintf($out, "{common.cannot_find_cfg_file}\n", $configfilename) && die);
334}
335
336
337
338sub use_collection {
339 my ($site, $collection, $collectdir) = @_;
340
341 if ((defined $site) && ($site ne ""))
342 {
343 return &util::use_site_collection($site, $collection, $collectdir);
344 }
345 else
346 {
347 return &util::use_collection($collection, $collectdir);
348 }
349}
350
351
3521;
353
354
Note: See TracBrowser for help on using the repository browser.