root/main/trunk/greenstone2/bin/script/incremental-import.pl @ 24362

Revision 24362, 4.9 KB (checked in by ak19, 8 years ago)

The method of locating perl has changed once more: util now defines the fuction get_perl_exec which is used by other scripts to obtain the path to the perl executable they should use.

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