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