source: gsdl/trunk/bin/script/incremental-buildcol.pl@ 18492

Last change on this file since 18492 was 18492, checked in by davidb, 15 years ago

incremental switches to -removeold if collection not built before

  • Property svn:executable set to *
File size: 3.4 KB
RevLine 
[18470]1#!/usr/bin/perl -w
2
3###########################################################################
4#
5# incremental-buildcol.pl -- runs buildcol.pl with -incremental on
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) 2009 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
29# This program is designed to support incremental building of Greenstone
30# Runs: buildcol.pl -incremental -builddir GSDLHOME/collect/$collect/index ...
31
32
33BEGIN {
34 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
35 die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
36 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
37}
38
39
40use strict;
41
42use util;
43
44
45sub main
46{
47 my ($argc,@argv) = @_;
48
49 if (($argc==0) || (($argc==1) && ($argv[0] =~ m/^--?h(elp)?$/))) {
50 my ($progname) = ($0 =~ m/^.*\/(.*?)$/);
51
52
53 print STDERR "\n";
54 print STDERR "Usage: $progname [buildcol.pl options] collection\n";
55 print STDERR "\n";
56
57 exit(-1);
58 }
59
60
61 my $collect = pop @argv;
62
[18492]63
64 my @filtered_argv = ();
65
66 my $collect_dir = undef;
67 my $build_dir = undef;
68
69 while (my $arg = shift @argv) {
70 if ($arg eq "-collectdir") {
71 $collect_dir = shift @argv;
72 push(@filtered_argv,$arg,$collect_dir);
73 }
74 elsif ($arg eq "-builddir") {
75 $build_dir = shift @argv;
76 push(@filtered_argv,$arg,$build_dir);
77 }
78 else {
79 push(@filtered_argv,$arg);
80 }
81 }
82
83
84 if (!defined $collect_dir) {
85 $collect_dir = &util::filename_cat($ENV{'GSDLHOME'},"collect",$collect);
86 }
[18470]87 if (!-d $collect_dir) {
88 print STDERR "Error: $collect_dir does not exist\n";
89 exit(-1);
90 }
91
[18492]92
93 if (!defined $build_dir) {
94 $build_dir = &util::filename_cat($collect_dir,"index");
95 push(@filtered_argv,"-builddir",$build_dir);
96 }
97
98 my $quoted_argv = join(" ", map { "\"$_\"" } @filtered_argv);
[18470]99
[18492]100 my $build_cfg_filename = &util::filename_cat($build_dir,"build.cfg");
[18470]101
[18492]102 my $buildcol_cmd = "buildcol.pl";
[18470]103
[18492]104 if (-e $build_cfg_filename) {
105 $buildcol_cmd .= " -incremental";
106 }
107 else {
108### print STDERR "$build_cfg_filename does not exist.\n";
109 print STDERR "*****\n";
110 print STDERR "* First time built. Switching to full buildcol.pl.\n";
111 print STDERR "*****\n";
112 $buildcol_cmd .= " -removeold";
113 }
114
[18470]115
[18492]116 $buildcol_cmd .= " $quoted_argv \"$collect\"";
[18470]117
118 my $buildcol_status = system($buildcol_cmd)/256;
119
120 if ($buildcol_status != 0) {
121 print STDERR "Error: Failed to run: $buildcol_cmd\n";
122 print STDERR " $!\n" if ($! ne "");
123 exit(-1);
124 }
125}
126
127&main(scalar(@ARGV),@ARGV);
128
129
130
131
Note: See TracBrowser for help on using the repository browser.