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