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

Last change on this file since 1761 was 1761, checked in by dmm9, 23 years ago

Removing obsolete documentation

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