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

Last change on this file since 27189 was 27189, checked in by davidb, 11 years ago

Some additional fields extracted/returned to collect config file that help support parallel building

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