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

Last change on this file since 1452 was 1431, checked in by sjboddie, 24 years ago

Made a few minor adjustments to perl building code for use with
collectoraction

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 9.2 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 " -out Filename or handle to print output status to.\n";
65 print STDERR " The default is STDERR\n\n";
66}
67
68
69sub main
70{
71 my ($verbosity, $archivedir, $cachedir, $builddir, $maxdocs,
72 $debug, $mode, $indexname, $keepold, $allclassifications,
73 $create_images, $out);
74 if (!parsargv::parse(\@ARGV,
75 'verbosity/\d+/2', \$verbosity,
76 'archivedir/.*/', \$archivedir,
77 'cachedir/.*/', \$cachedir,
78 'builddir/.*/', \$builddir,
79 'maxdocs/^\-?\d+/-1', \$maxdocs,
80 'debug', \$debug,
81 'mode/^(all|compress_text|build_index|infodb)$/all', \$mode,
82 'index/.*/', \$indexname,
83 'keepold', \$keepold,
84 'allclassifications', \$allclassifications,
85 'create_images', \$create_images,
86 'out/.*/STDERR', \$out)) {
87 &print_usage();
88 die "\n";
89 }
90
91 my $close_out = 0;
92 if ($out !~ /^(STDERR|STDOUT)$/i) {
93 open (OUT, ">$out") || die "Couldn't open output file $out\n";
94 $out = "buildcol::OUT";
95 $close_out = 1;
96 }
97 $out->autoflush(1);
98
99 # get and check the collection
100 if (($collection = &util::use_collection(@ARGV)) eq "") {
101 &print_usage();
102 die "\n";
103 }
104
105 # read the configuration file
106 $textindex = "section:text";
107 $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc", "collect.cfg");
108 if (-e $configfilename) {
109 $collectcfg = &colcfg::read_collect_cfg ($configfilename);
110 if (defined $collectcfg->{'archivedir'} && $archivedir eq "") {
111 $archivedir = $collectcfg->{'archivedir'};
112 }
113 if (defined $collectcfg->{'cachedir'} && $cachedir eq "") {
114 $cachedir = $collectcfg->{'cachedir'};
115 }
116 if (defined $collectcfg->{'builddir'} && $builddir eq "") {
117 $builddir = $collectcfg->{'builddir'};
118 }
119 } else {
120 die "Couldn't find the configuration file $configfilename\n";
121 }
122
123 # create default images if required
124 if ($create_images) {
125 my $collection_name = $collection;
126 $collection_name = $collectcfg->{'collectionmeta'}->{'collectionname'}
127 if defined $collectcfg->{'collectionmeta'}->{'collectionname'};
128
129 &create_images ($collection_name);
130 }
131
132 # fill in the default archives and building directories if none
133 # were supplied, turn all \ into / and remove trailing /
134 $archivedir = "$ENV{'GSDLCOLLECTDIR'}/archives" if $archivedir eq "";
135 $archivedir =~ s/[\\\/]+/\//g;
136 $archivedir =~ s/\/$//;
137 $builddir = "$ENV{'GSDLCOLLECTDIR'}/building" if $builddir eq "";
138 $builddir =~ s/[\\\/]+/\//g;
139 $builddir =~ s/\/$//;
140
141 # update the archive cache if needed
142 if ($cachedir) {
143 print $out "Updating archive cache\n" if ($verbosity >= 1);
144
145 $cachedir =~ s/[\\\/]+$//;
146 $cachedir .= "/collect/$collection" unless
147 $cachedir =~ /collect\/$collection/;
148
149 $realarchivedir = "$cachedir/archives";
150 $realbuilddir = "$cachedir/building";
151 &util::mk_all_dir ($realarchivedir);
152 &util::mk_all_dir ($realbuilddir);
153 &util::cachedir ($archivedir, $realarchivedir, $verbosity);
154
155 } else {
156 $realarchivedir = $archivedir;
157 $realbuilddir = $builddir;
158 }
159
160 # build it in realbuilddir
161 &util::mk_all_dir ($realbuilddir);
162
163
164 # if a builder class has been created for this collection, use it
165 # otherwise, use the mg builder
166 if (-e "$ENV{'GSDLCOLLECTDIR'}/perllib/${collection}builder.pm") {
167 $builderdir = "$ENV{'GSDLCOLLECTDIR'}/perllib";
168 $buildertype = "${collection}builder";
169 } else {
170 $builderdir = "$ENV{'GSDLHOME'}/perllib";
171 $buildertype = "mgbuilder";
172 }
173
174 require "$builderdir/$buildertype.pm";
175
176 eval("\$builder = new $buildertype(\$collection, " .
177 "\$realarchivedir, \$realbuilddir, \$verbosity, " .
178 "\$maxdocs, \$debug, \$keepold, \$allclassifications, \$out)");
179 die "$@" if $@;
180
181 $builder->init();
182
183 if ($mode =~ /^all$/i) {
184 $builder->compress_text($textindex);
185 $builder->build_indexes($indexname);
186 $builder->make_infodatabase();
187 $builder->collect_specific();
188 } elsif ($mode =~ /^compress_text$/i) {
189 $builder->compress_text($textindex);
190 } elsif ($mode =~ /^build_index$/i) {
191 $builder->build_indexes($indexname);
192 } elsif ($mode =~ /^infodb$/i) {
193 $builder->make_infodatabase();
194 } else {
195 die "unknown mode: $mode\n";
196 }
197
198 $builder->make_auxiliary_files() if !$debug;
199 $builder->deinit();
200
201 if (($realbuilddir ne $builddir) && !$debug) {
202 print $out "Copying back the cached build\n" if ($verbosity >= 1);
203 &util::rm_r ($builddir);
204 &util::cp_r ($realbuilddir, $builddir);
205 }
206
207 close OUT if $close_out;
208}
209
210sub create_images {
211 my ($collection_name) = @_;
212
213 my $image_script = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "script", "gimp", "title_icon.pl");
214 if (!-e $image_script) {
215 print $out "WARNING: Image making script ($image_script) could not be found\n";
216 print $out " Default images will not be generated\n\n";
217 return;
218 }
219
220 my $imagedir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "images");
221
222 &util::mk_all_dir ($imagedir);
223
224 # create the images
225 system ("$image_script -size 1.5 -image_dir \"$imagedir\" -filename $collection.gif -text \"$collection_name\"");
226 system ("$image_script -image_dir \"$imagedir\" -filename ${collection}sm.gif -text \"$collection_name\"");
227
228 # update the collect.cfg configuration file (this will need
229 # to be changed when the config file format changes)
230 if (!open (CFGFILE, $configfilename)) {
231 print $out "WARNING: Couldn't open config file ($configfilename)\n";
232 print $out " for updating so collection images may not be linked correctly\n";
233 return;
234 }
235
236 my $line = ""; my $file = "";
237 my $found = 0; my $foundsm = 0;
238 while (defined ($line = <CFGFILE>)) {
239 if ($line =~ /collectionmeta\s+iconcollection\s+/) {
240 $line = "collectionmeta iconcollection _httpprefix_/collect/$collection/images/$collection.gif\n";
241 $found = 1;
242 } elsif ($line =~ /collectionmeta\s+iconcollectionsmall\s+/) {
243 $line = "collectionmeta iconcollectionsmall _httpprefix_/collect/$collection/images/${collection}sm.gif\n";
244 $foundsm = 1;
245 }
246 $file .= $line;
247 }
248 close CFGFILE;
249
250 $file .= "collectionmeta iconcollection _httpprefix_/collect/$collection/images/$collection.gif\n" if !$found;
251 $file .= "collectionmeta iconcollectionsmall _httpprefix_/collect/$collection/images/${collection}sm.gif\n" if !$foundsm;
252
253 if (!open (CFGFILE, ">$configfilename")) {
254 print $out "WARNING: Couldn't open config file ($configfilename)\n";
255 print $out " for updating so collection images may not be linked correctly\n";
256 return;
257 }
258 print CFGFILE $file;
259 close CFGFILE;
260}
Note: See TracBrowser for help on using the repository browser.