source: trunk/gsdl/bin/script/buildcol.pl@ 1644

Last change on this file since 1644 was 1644, checked in by paynter, 24 years ago

Reverted to version 1.20 (no mention of phind).

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 9.5 KB
Line 
1#!/usr/bin/perl -w
2
3###########################################################################
4#
5# buildcol.pl -- This program will build a particular collection
6# A component of the Greenstone digital library software
7# from the New Zealand Digital Library Project at the
8# University of Waikato, New Zealand.
9#
10# Copyright (C) 1999 New Zealand Digital Library Project
11#
12# This program is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License as published by
14# the Free Software Foundation; either version 2 of the License, or
15# (at your option) any later version.
16#
17# This program is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20# GNU General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
23# along with this program; if not, write to the Free Software
24# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25#
26###########################################################################
27
28package buildcol;
29
30BEGIN {
31 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
32 die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
33 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
34 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugins");
35 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/classify");
36}
37
38use colcfg;
39use parsargv;
40use util;
41use FileHandle;
42
43&main();
44
45sub print_usage {
46 print STDERR "\n usage: $0 [options] collection-name\n\n";
47 print STDERR " options:\n";
48 print STDERR " -verbosity number 0=none, 3=lots\n";
49 print STDERR " -archivedir directory Where the archives live\n";
50 print STDERR " -cachedir directory Where to cache the archives\n";
51 print STDERR " -builddir directory Where to put the built indexes\n";
52 print STDERR " -maxdocs number Maximum number of documents to build\n";
53 print STDERR " -debug Print output to STDOUT\n";
54 print STDERR " -mode all|compress_text|build_index|infodb\n";
55 print STDERR " -index indexname Index to build (will build all in\n";
56 print STDERR " config file if not set)\n";
57 print STDERR " -keepold will not destroy the current contents of the\n";
58 print STDERR " building directory\n";
59 print STDERR " -allclassifications Don't remove empty classifications\n";
60 print STDERR " -create_images Attempt to create default images for new\n";
61 print STDERR " collection. This relies on the Gimp being\n";
62 print STDERR " installed along with relevant perl modules\n";
63 print STDERR " to allow scripting from perl\n";
64 print STDERR " -collectdir directory Collection directory (defaults to " .
65 &util::filename_cat ($ENV{'GSDLHOME'}, "collect") . ")\n";
66 print STDERR " -out Filename or handle to print output status to.\n";
67 print STDERR " The default is STDERR\n\n";
68}
69
70
71sub main
72{
73 my ($verbosity, $archivedir, $cachedir, $builddir, $maxdocs,
74 $debug, $mode, $indexname, $keepold, $allclassifications,
75 $create_images, $collectdir, $out);
76 if (!parsargv::parse(\@ARGV,
77 'verbosity/\d+/2', \$verbosity,
78 'archivedir/.*/', \$archivedir,
79 'cachedir/.*/', \$cachedir,
80 'builddir/.*/', \$builddir,
81 'maxdocs/^\-?\d+/-1', \$maxdocs,
82 'debug', \$debug,
83 'mode/^(all|compress_text|build_index|infodb)$/all', \$mode,
84 'index/.*/', \$indexname,
85 'keepold', \$keepold,
86 'allclassifications', \$allclassifications,
87 'create_images', \$create_images,
88 'collectdir/.*/', \$collectdir,
89 'out/.*/STDERR', \$out)) {
90 &print_usage();
91 die "\n";
92 }
93
94 my $close_out = 0;
95 if ($out !~ /^(STDERR|STDOUT)$/i) {
96 open (OUT, ">$out") || die "Couldn't open output file $out\n";
97 $out = "buildcol::OUT";
98 $close_out = 1;
99 }
100 $out->autoflush(1);
101
102 # get and check the collection
103 if (($collection = &util::use_collection(@ARGV, $collectdir)) eq "") {
104 &print_usage();
105 die "\n";
106 }
107
108 # read the configuration file
109 $textindex = "section:text";
110 $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc", "collect.cfg");
111 if (-e $configfilename) {
112 $collectcfg = &colcfg::read_collect_cfg ($configfilename);
113 if (defined $collectcfg->{'archivedir'} && $archivedir eq "") {
114 $archivedir = $collectcfg->{'archivedir'};
115 }
116 if (defined $collectcfg->{'cachedir'} && $cachedir eq "") {
117 $cachedir = $collectcfg->{'cachedir'};
118 }
119 if (defined $collectcfg->{'builddir'} && $builddir eq "") {
120 $builddir = $collectcfg->{'builddir'};
121 }
122 } else {
123 die "Couldn't find the configuration file $configfilename\n";
124 }
125
126 # create default images if required
127 if ($create_images) {
128 my $collection_name = $collection;
129 $collection_name = $collectcfg->{'collectionmeta'}->{'collectionname'}
130 if defined $collectcfg->{'collectionmeta'}->{'collectionname'};
131
132 &create_images ($collection_name);
133 }
134
135 # fill in the default archives and building directories if none
136 # were supplied, turn all \ into / and remove trailing /
137 $archivedir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "archives") if $archivedir eq "";
138 $archivedir =~ s/[\\\/]+/\//g;
139 $archivedir =~ s/\/$//;
140 $builddir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "building") if $builddir eq "";
141 $builddir =~ s/[\\\/]+/\//g;
142 $builddir =~ s/\/$//;
143
144 # update the archive cache if needed
145 if ($cachedir) {
146 print $out "Updating archive cache\n" if ($verbosity >= 1);
147
148 $cachedir =~ s/[\\\/]+$//;
149 $cachedir .= "/collect/$collection" unless
150 $cachedir =~ /collect\/$collection/;
151
152 $realarchivedir = "$cachedir/archives";
153 $realbuilddir = "$cachedir/building";
154 &util::mk_all_dir ($realarchivedir);
155 &util::mk_all_dir ($realbuilddir);
156 &util::cachedir ($archivedir, $realarchivedir, $verbosity);
157
158 } else {
159 $realarchivedir = $archivedir;
160 $realbuilddir = $builddir;
161 }
162
163 # build it in realbuilddir
164 &util::mk_all_dir ($realbuilddir);
165
166
167 # if a builder class has been created for this collection, use it
168 # otherwise, use the mg builder
169 if (-e "$ENV{'GSDLCOLLECTDIR'}/perllib/${collection}builder.pm") {
170 $builderdir = "$ENV{'GSDLCOLLECTDIR'}/perllib";
171 $buildertype = "${collection}builder";
172 } else {
173 $builderdir = "$ENV{'GSDLHOME'}/perllib";
174 $buildertype = "mgbuilder";
175 }
176
177 require "$builderdir/$buildertype.pm";
178
179 eval("\$builder = new $buildertype(\$collection, " .
180 "\$realarchivedir, \$realbuilddir, \$verbosity, " .
181 "\$maxdocs, \$debug, \$keepold, \$allclassifications, \$out)");
182 die "$@" if $@;
183
184 $builder->init();
185
186 if ($mode =~ /^all$/i) {
187 $builder->compress_text($textindex);
188 $builder->build_indexes($indexname);
189 $builder->make_infodatabase();
190 $builder->collect_specific();
191 } elsif ($mode =~ /^compress_text$/i) {
192 $builder->compress_text($textindex);
193 } elsif ($mode =~ /^build_index$/i) {
194 $builder->build_indexes($indexname);
195 } elsif ($mode =~ /^infodb$/i) {
196 $builder->make_infodatabase();
197 } else {
198 die "unknown mode: $mode\n";
199 }
200
201 $builder->make_auxiliary_files() if !$debug;
202 $builder->deinit();
203
204 if (($realbuilddir ne $builddir) && !$debug) {
205 print $out "Copying back the cached build\n" if ($verbosity >= 1);
206 &util::rm_r ($builddir);
207 &util::cp_r ($realbuilddir, $builddir);
208 }
209
210 close OUT if $close_out;
211}
212
213sub create_images {
214 my ($collection_name) = @_;
215
216 my $image_script = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "script", "gimp", "title_icon.pl");
217 if (!-e $image_script) {
218 print $out "WARNING: Image making script ($image_script) could not be found\n";
219 print $out " Default images will not be generated\n\n";
220 return;
221 }
222
223 my $imagedir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "images");
224
225 &util::mk_all_dir ($imagedir);
226
227 # create the images
228 system ("$image_script -size 1.5 -image_dir \"$imagedir\" -filename $collection.gif -text \"$collection_name\"");
229 system ("$image_script -image_dir \"$imagedir\" -filename ${collection}sm.gif -text \"$collection_name\"");
230
231 # update the collect.cfg configuration file (this will need
232 # to be changed when the config file format changes)
233 if (!open (CFGFILE, $configfilename)) {
234 print $out "WARNING: Couldn't open config file ($configfilename)\n";
235 print $out " for updating so collection images may not be linked correctly\n";
236 return;
237 }
238
239 my $line = ""; my $file = "";
240 my $found = 0; my $foundsm = 0;
241 while (defined ($line = <CFGFILE>)) {
242 if ($line =~ /collectionmeta\s+iconcollection\s+/) {
243 $line = "collectionmeta iconcollection _httpprefix_/collect/$collection/images/$collection.gif\n";
244 $found = 1;
245 } elsif ($line =~ /collectionmeta\s+iconcollectionsmall\s+/) {
246 $line = "collectionmeta iconcollectionsmall _httpprefix_/collect/$collection/images/${collection}sm.gif\n";
247 $foundsm = 1;
248 }
249 $file .= $line;
250 }
251 close CFGFILE;
252
253 $file .= "collectionmeta iconcollection _httpprefix_/collect/$collection/images/$collection.gif\n" if !$found;
254 $file .= "collectionmeta iconcollectionsmall _httpprefix_/collect/$collection/images/${collection}sm.gif\n" if !$foundsm;
255
256 if (!open (CFGFILE, ">$configfilename")) {
257 print $out "WARNING: Couldn't open config file ($configfilename)\n";
258 print $out " for updating so collection images may not be linked correctly\n";
259 return;
260 }
261 print CFGFILE $file;
262 close CFGFILE;
263}
Note: See TracBrowser for help on using the repository browser.