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