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

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

plugins now take options

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 KB
Line 
1#!/usr/local/bin/perl5 -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
28BEGIN {
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}
34
35use colcfg;
36use parsargv;
37use util;
38
39&main();
40
41sub print_usage {
42 print STDERR "\n usage: $0 [options] collection-name\n\n";
43 print STDERR " options:\n";
44 print STDERR " -verbosity number 0=none, 3=lots\n";
45 print STDERR " -archivedir directory Where the archives live\n";
46 print STDERR " -cachedir directory Where to cache the archives\n";
47 print STDERR " -builddir directory Where to put the built indexes\n";
48 print STDERR " -maxdocs number Maximum number of documents to build\n";
49 print STDERR " -debug Print output to STDOUT\n";
50 print STDERR " -mode all|compress_text|build_index|infodb\n";
51 print STDERR " -index indexname Index to build (will build all in\n";
52 print STDERR " config file if not set)\n";
53 print STDERR " -keepold will not destroy the current contents of the\n";
54 print STDERR " building directory\n";
55 print STDERR " -allclassifications Don't remove empty classifications\n\n";
56}
57
58
59sub main
60{
61 my ($verbosity, $archivedir, $cachedir, $builddir, $maxdocs,
62 $debug, $mode, $indexname, $keepold, $allclassifications);
63 if (!parsargv::parse(\@ARGV,
64 'verbosity/\d+/2', \$verbosity,
65 'archivedir/.*/', \$archivedir,
66 'cachedir/.*/', \$cachedir,
67 'builddir/.*/', \$builddir,
68 'maxdocs/^\-?\d+/-1', \$maxdocs,
69 'debug', \$debug,
70 'mode/^(all|compress_text|build_index|infodb)$/all', \$mode,
71 'index/.*/', \$indexname,
72 'keepold', \$keepold,
73 'allclassifications', \$allclassifications)) {
74 &print_usage();
75 die "\n";
76 }
77
78 # get and check the collection
79 if (($collection = &util::use_collection(@ARGV)) eq "") {
80 &print_usage();
81 die "\n";
82 }
83
84 # read the configuration file
85 $textindex = "section:text";
86 $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc/collect.cfg");
87 if (-e $configfilename) {
88 $collectcfg = &colcfg::read_collect_cfg ($configfilename);
89 if (defined $collectcfg->{'archivedir'} && $archivedir eq "") {
90 $archivedir = $collectcfg->{'archivedir'};
91 }
92 if (defined $collectcfg->{'cachedir'} && $cachedir eq "") {
93 $cachedir = $collectcfg->{'cachedir'};
94 }
95 if (defined $collectcfg->{'builddir'} && $builddir eq "") {
96 $builddir = $collectcfg->{'builddir'};
97 }
98 } else {
99 die "Couldn't find the configuration file $configfilename\n";
100 }
101
102 # fill in the default archives and building directories if none
103 # were supplied, turn all \ into / and remove trailing /
104 $archivedir = "$ENV{'GSDLCOLLECTDIR'}/archives" if $archivedir eq "";
105 $archivedir =~ s/[\\\/]+/\//g;
106 $archivedir =~ s/\/$//;
107 $builddir = "$ENV{'GSDLCOLLECTDIR'}/building" if $builddir eq "";
108 $builddir =~ s/[\\\/]+/\//g;
109 $builddir =~ s/\/$//;
110
111 # update the archive cache if needed
112 if ($cachedir) {
113 print STDERR "Updating archive cache\n" if ($verbosity >= 1);
114
115 $cachedir =~ s/[\\\/]+$//;
116 $cachedir .= "/collect/$collection" unless
117 $cachedir =~ /collect\/$collection/;
118
119 $realarchivedir = "$cachedir/archives";
120 $realbuilddir = "$cachedir/building";
121 &util::mk_all_dir ($realarchivedir);
122 &util::mk_all_dir ($realbuilddir);
123 &util::cachedir ($archivedir, $realarchivedir, $verbosity);
124
125 } else {
126 $realarchivedir = $archivedir;
127 $realbuilddir = $builddir;
128 }
129
130 # build it in realbuilddir
131 &util::mk_all_dir ($realbuilddir);
132
133
134 # if a builder class has been created for this collection, use it
135 # otherwise, use the mg builder
136 if (-e "$ENV{'GSDLCOLLECTDIR'}/perllib/${collection}builder.pm") {
137 $builderdir = "$ENV{'GSDLCOLLECTDIR'}/perllib";
138 $buildertype = "${collection}builder";
139 } else {
140 $builderdir = "$ENV{'GSDLHOME'}/perllib";
141 $buildertype = "mgbuilder";
142 }
143
144 require "$builderdir/$buildertype.pm";
145
146 eval("\$builder = new $buildertype(\$collection, " .
147 "\$realarchivedir, \$realbuilddir, \$verbosity, " .
148 "\$maxdocs, \$debug, \$keepold, \$allclassifications)");
149 die "$@" if $@;
150
151 $builder->init();
152
153 if ($mode =~ /^all$/i) {
154 $builder->compress_text($textindex);
155 $builder->build_indexes($indexname);
156 $builder->make_infodatabase();
157 $builder->collect_specific();
158 } elsif ($mode =~ /^compress_text$/i) {
159 $builder->compress_text($textindex);
160 } elsif ($mode =~ /^build_index$/i) {
161 $builder->build_indexes($indexname);
162 } elsif ($mode =~ /^infodb$/i) {
163 $builder->make_infodatabase();
164 } else {
165 die "unknown mode: $mode\n";
166 }
167
168 $builder->make_auxiliary_files() if !$debug;
169 $builder->deinit();
170
171 if (($realbuilddir ne $builddir) && !$debug) {
172 print STDERR "Copying back the cached build\n" if ($verbosity >= 1);
173 &util::rm_r ($builddir);
174 &util::cp_r ($realbuilddir, $builddir);
175 }
176}
177
178
Note: See TracBrowser for help on using the repository browser.