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

Last change on this file since 546 was 538, checked in by sjboddie, 25 years ago

added GPL header

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 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 " -allclassifications Don't remove empty classifications\n\n";
50}
51
52
53sub main
54{
55 if (!parsargv::parse(\@ARGV,
56 'verbosity/\d+/2', \$verbosity,
57 'archivedir/.*/', \$archivedir,
58 'cachedir/.*/', \$cachedir,
59 'builddir/.*/', \$builddir,
60 'maxdocs/\d+/', \$maxdocs,
61 'allclassifications', \$allclassifications)) {
62 &print_usage();
63 die "\n";
64 }
65
66 # get and check the collection
67 if (($collection = &util::use_collection(@ARGV)) eq "") {
68 &print_usage();
69 die "\n";
70 }
71
72 # only here to prevent a perl warning
73 $maxdocs = "" if $maxdocs !~ /\d/;
74 $allclassifications = 0 unless $allclassifications == 1;
75
76 # read the configuration file
77 $textindex = "section:text";
78 $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc/collect.cfg");
79 if (-e $configfilename) {
80 $collectcfg = &colcfg::read_collect_cfg ($configfilename);
81 if (defined $collectcfg->{'archivedir'} && $archivedir eq "") {
82 $archivedir = $collectcfg->{'archivedir'};
83 }
84 if (defined $collectcfg->{'cachedir'} && $cachedir eq "") {
85 $cachedir = $collectcfg->{'cachedir'};
86 }
87 if (defined $collectcfg->{'builddir'} && $builddir eq "") {
88 $builddir = $collectcfg->{'builddir'};
89 }
90 if (defined $collectcfg->{'textindex'}) {
91 $textindex = $collectcfg->{'textindex'};
92 }
93 } else {
94 die "Couldn't find the configuration file $configfilename\n";
95 }
96
97 # fill in the default archives and building directories if none
98 # were supplied, turn all \ into / and remove trailing /
99 $archivedir = "$ENV{'GSDLCOLLECTDIR'}/archives" if $archivedir eq "";
100 $archivedir =~ s/[\\\/]+/\//g;
101 $archivedir =~ s/\/$//;
102 $builddir = "$ENV{'GSDLCOLLECTDIR'}/building" if $builddir eq "";
103 $builddir =~ s/[\\\/]+/\//g;
104 $builddir =~ s/\/$//;
105
106 # update the archive cache if needed
107 if ($cachedir) {
108 print STDERR "Updating archive cache\n" if ($verbosity >= 1);
109
110 $cachedir =~ s/[\\\/]+$//;
111 $cachedir .= "/collect/$collection" unless
112 $cachedir =~ /collect\/$collection/;
113
114 $realarchivedir = "$cachedir/archives";
115 $realbuilddir = "$cachedir/building";
116 &util::mk_all_dir ($realarchivedir);
117 &util::mk_all_dir ($realbuilddir);
118 &util::cachedir ($archivedir, $realarchivedir, $verbosity);
119
120 } else {
121 $realarchivedir = $archivedir;
122 $realbuilddir = $builddir;
123 }
124
125 # build it in realbuilddir
126 &util::mk_all_dir ($realbuilddir);
127
128
129 # if a builder class has been created for this collection, use it
130 # otherwise, use the mg builder
131 if (-e "$ENV{'GSDLCOLLECTDIR'}/perllib/${collection}builder.pm") {
132 $builderdir = "$ENV{'GSDLCOLLECTDIR'}/perllib";
133 $buildertype = "${collection}builder";
134 } else {
135 $builderdir = "$ENV{'GSDLHOME'}/perllib";
136 $buildertype = "mgbuilder";
137 }
138
139 require "$builderdir/$buildertype.pm";
140
141 eval("\$builder = new $buildertype(\$collection, " .
142 "\$realarchivedir, \$realbuilddir, \$verbosity, " .
143 "\$maxdocs, \$allclassifications)");
144 die "$@" if $@;
145
146 $builder->init();
147 $builder->compress_text($textindex);
148 $builder->build_indexes();
149 $builder->make_infodatabase();
150 $builder->make_auxiliary_files();
151 $builder->deinit();
152
153
154 if ($realbuilddir ne $builddir) {
155 print STDERR "Copying back the cached build\n" if ($verbosity >= 1);
156 &util::rm_r ($builddir);
157 &util::cp_r ($realbuilddir, $builddir);
158 }
159}
160
161
Note: See TracBrowser for help on using the repository browser.