source: main/trunk/greenstone2/bin/script/incremental-import.pl@ 24192

Last change on this file since 24192 was 24192, checked in by ak19, 13 years ago

Sam discovered that using dollar-Config{perlpath} in place of dollar-hat-X is the better way to obtain the path to the perl that is being used. We hope this will not be a relative path on the Mac as dollar-hat-x was on Professor Witten's Mac when we tried it there today.

  • Property svn:executable set to *
File size: 5.4 KB
Line 
1#!/usr/bin/perl -w
2
3###########################################################################
4#
5# full-import.pl -- runs import.pl with -incremental option 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: import.pl -incremental ...
31
32
33
34BEGIN {
35 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
36 die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
37 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
38}
39
40
41use strict;
42
43use Config; # for getting the perlpath in the recommended way
44use dbutil;
45use util;
46use colcfg;
47
48sub main
49{
50 my ($argc,@argv) = @_;
51
52 if (($argc==0) || (($argc==1) && ($argv[0] =~ m/^--?h(elp)?$/))) {
53 my ($progname) = ($0 =~ m/^.*[\/|\\](.*?)$/);
54
55
56 print STDERR "\n";
57 print STDERR "Usage: $progname [import.pl options] collection\n";
58 print STDERR "\n";
59
60 exit(-1);
61 }
62
63
64 my $collection = pop @argv;
65
66 my @filtered_argv = ();
67
68 my $collect_dir = undef;
69 my $archive_dir = undef;
70 my $site = undef;
71 my $manifest = undef;
72
73 while (my $arg = shift @argv) {
74 # No actual filtering happens at the moment (@filterd_argv == @argv)
75 # Useful to do it this way if we want incremental-import.pl
76 # to start accepting its own arguments that are different to import.pl
77
78 if ($arg eq "-collectdir") {
79 $collect_dir = shift @argv;
80 push(@filtered_argv,$arg,$collect_dir);
81 }
82 elsif ($arg eq "-archivedir") {
83 $archive_dir = shift @argv;
84 push(@filtered_argv,$arg,$archive_dir);
85 }
86 elsif ($arg eq "-site") {
87 $site = shift @argv;
88 push(@filtered_argv,$arg,$site);
89 }
90 elsif ($arg eq "-manifest") {
91 $manifest = shift @argv;
92 push(@filtered_argv,$arg,$manifest);
93 }
94 else {
95 push(@filtered_argv,$arg);
96 }
97 }
98
99 # get and check the collection name
100 if ((&colcfg::use_collection($site, $collection, $collect_dir)) eq "") {
101 print STDERR "Unable to use collection \"$collection\" within \"$collect_dir\"\n";
102 exit -1;
103 }
104 my $gs_mode = "gs2";
105 if ((defined $site) && ($site ne "")) {
106 $gs_mode = "gs3";
107 }
108
109 if (!defined $archive_dir) {
110 $archive_dir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "archives");
111 }
112 my $etcdir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc");
113 # BACKWARDS COMPATIBILITY: Just in case there are old .ldb/.bdb files (won't do anything for other infodbtypes)
114 &util::rename_ldb_or_bdb_file(&util::filename_cat($archive_dir, "archiveinf-doc"));
115
116 my $col_cfg_file;
117 if ($gs_mode eq "gs3") {
118 $col_cfg_file = &util::filename_cat($etcdir, "collectionConfig.xml");
119 } else {
120 $col_cfg_file = &util::filename_cat($etcdir, "collect.cfg");
121 }
122
123 my $collect_cfg = &colcfg::read_collection_cfg ($col_cfg_file, $gs_mode);
124 # get the database type for this collection from its configuration file (may be undefined)
125 my $infodbtype = $collect_cfg->{'infodbtype'} || &dbutil::get_default_infodb_type();
126 $infodbtype = "gdbm" if $infodbtype eq "gdbm-txtgz";
127 my $archiveinf_doc_file_path = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archive_dir);
128
129 my $quoted_argv = join(" ", map { "\"$_\"" } @filtered_argv);
130
131
132 my $import_cmd = "import.pl";
133 if($ENV{'PERLPATH'}) {
134 # need to ensure that the path to perl is quoted (in case there's spaces in it)
135 if($ENV{'GSDLOS'} =~ m/windows/) {
136 $import_cmd = "\"$ENV{'PERLPATH'}\\Perl.exe\" -S $import_cmd";
137 } else {
138 $import_cmd = "\"$ENV{'PERLPATH'}/perl\" -S $import_cmd";
139 }
140 } else {
141 #Config{perlpath}, like $^X, is a special variable containing the full path to the current perl executable we are in
142 $import_cmd = "\"$Config{perlpath}\" -S $import_cmd";
143 }
144
145 if (defined $manifest) {
146 # manifest files need -keepold not -incremental
147 $import_cmd .= " -keepold";
148 } else {
149 if (-e $archiveinf_doc_file_path) {
150 $import_cmd .= " -incremental";
151
152 }
153 else {
154 print STDERR "*****\n";
155 print STDERR "First time import. Switching to full import.pl.\n";
156 print STDERR "*****\n";
157 $import_cmd .= " -removeold";
158 }
159 }
160 $import_cmd .= " $quoted_argv \"$collection\"";
161
162
163 my $import_status = system($import_cmd)/256;
164
165 if ($import_status != 0) {
166 print STDERR "Error: Failed to run: $import_cmd\n";
167 print STDERR " $!\n" if ($! ne "");
168 exit(-1);
169 }
170}
171
172&main(scalar(@ARGV),@ARGV);
Note: See TracBrowser for help on using the repository browser.