source: trunk/gsdl/bin/script/mgppbuildcol.pl@ 1693

Last change on this file since 1693 was 1693, checked in by kjm18, 23 years ago

updated to resemble the updated buildcol.pl

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