[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 | BEGIN {
|
---|
| 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 |
|
---|
[18470] | 39 | use strict;
|
---|
[21664] | 40 | use dbutil;
|
---|
[18491] | 41 | use util;
|
---|
[21733] | 42 | use colcfg;
|
---|
[18470] | 43 |
|
---|
[18491] | 44 | sub main
|
---|
| 45 | {
|
---|
| 46 | my ($argc,@argv) = @_;
|
---|
[18470] | 47 |
|
---|
[18491] | 48 | if (($argc==0) || (($argc==1) && ($argv[0] =~ m/^--?h(elp)?$/))) {
|
---|
[20606] | 49 | my ($progname) = ($0 =~ m/^.*[\/|\\](.*?)$/);
|
---|
[18470] | 50 |
|
---|
[18491] | 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 |
|
---|
[21733] | 59 | my $collection = pop @argv;
|
---|
[18491] | 60 |
|
---|
| 61 | my @filtered_argv = ();
|
---|
| 62 |
|
---|
| 63 | my $collect_dir = undef;
|
---|
| 64 | my $archive_dir = undef;
|
---|
[21733] | 65 | my $site = undef;
|
---|
[23218] | 66 | my $manifest = undef;
|
---|
[18491] | 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 | }
|
---|
[21733] | 81 | elsif ($arg eq "-site") {
|
---|
| 82 | $site = shift @argv;
|
---|
| 83 | push(@filtered_argv,$arg,$site);
|
---|
| 84 | }
|
---|
[23218] | 85 | elsif ($arg eq "-manifest") {
|
---|
| 86 | $manifest = shift @argv;
|
---|
| 87 | push(@filtered_argv,$arg,$manifest);
|
---|
| 88 | }
|
---|
[18491] | 89 | else {
|
---|
| 90 | push(@filtered_argv,$arg);
|
---|
| 91 | }
|
---|
| 92 | }
|
---|
[21733] | 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;
|
---|
[23052] | 98 | }
|
---|
| 99 | my $gs_mode = "gs2";
|
---|
| 100 | if ((defined $site) && ($site ne "")) {
|
---|
| 101 | $gs_mode = "gs3";
|
---|
| 102 | }
|
---|
| 103 |
|
---|
[18491] | 104 | if (!defined $archive_dir) {
|
---|
[23052] | 105 | $archive_dir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "archives");
|
---|
[18491] | 106 | }
|
---|
[23052] | 107 | my $etcdir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc");
|
---|
[21664] | 108 | # BACKWARDS COMPATIBILITY: Just in case there are old .ldb/.bdb files (won't do anything for other infodbtypes)
|
---|
[21732] | 109 | &util::rename_ldb_or_bdb_file(&util::filename_cat($archive_dir, "archiveinf-doc"));
|
---|
[18491] | 110 |
|
---|
[23052] | 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 | }
|
---|
[21664] | 117 |
|
---|
[23052] | 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();
|
---|
[23168] | 121 | $infodbtype = "gdbm" if $infodbtype eq "gdbm-txtgz";
|
---|
[23052] | 122 | my $archiveinf_doc_file_path = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archive_dir);
|
---|
| 123 |
|
---|
[18491] | 124 | my $quoted_argv = join(" ", map { "\"$_\"" } @filtered_argv);
|
---|
| 125 |
|
---|
[20925] | 126 | # need to ensure that the path to perl is quoted (in case there's spaces in it)
|
---|
[24362] | 127 | my $import_cmd = "\"".&util::get_perl_exec()."\" -S import.pl";
|
---|
[20925] | 128 |
|
---|
[23218] | 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 | }
|
---|
[18491] | 143 | }
|
---|
[21733] | 144 | $import_cmd .= " $quoted_argv \"$collection\"";
|
---|
[18491] | 145 |
|
---|
[18492] | 146 |
|
---|
[18491] | 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 | }
|
---|
[18470] | 154 | }
|
---|
| 155 |
|
---|
[18491] | 156 | &main(scalar(@ARGV),@ARGV);
|
---|