[21861] | 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 | 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 |
|
---|
| 39 | use strict;
|
---|
| 40 | use dbutil;
|
---|
| 41 | use util;
|
---|
| 42 | use colcfg;
|
---|
| 43 |
|
---|
| 44 | sub 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 |
|
---|
| 67 | while (my $arg = shift @argv) {
|
---|
| 68 | # No actual filtering happens at the moment (@filterd_argv == @argv)
|
---|
| 69 | # Useful to do it this way if we want incremental-import.pl
|
---|
| 70 | # to start accepting its own arguments that are different to import.pl
|
---|
| 71 |
|
---|
| 72 | if ($arg eq "-collectdir") {
|
---|
| 73 | $collect_dir = shift @argv;
|
---|
| 74 | push(@filtered_argv,$arg,$collect_dir);
|
---|
| 75 | }
|
---|
| 76 | elsif ($arg eq "-archivedir") {
|
---|
| 77 | $archive_dir = shift @argv;
|
---|
| 78 | push(@filtered_argv,$arg,$archive_dir);
|
---|
| 79 | }
|
---|
| 80 | elsif ($arg eq "-site") {
|
---|
| 81 | $site = shift @argv;
|
---|
| 82 | push(@filtered_argv,$arg,$site);
|
---|
| 83 | }
|
---|
| 84 | else {
|
---|
| 85 | push(@filtered_argv,$arg);
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | # get and check the collection name
|
---|
| 90 | if ((&colcfg::use_collection($site, $collection, $collect_dir)) eq "") {
|
---|
| 91 | print STDERR "Unable to use collection \"$collection\" within \"$collect_dir\"\n";
|
---|
| 92 | exit -1;
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | if (!defined $archive_dir) {
|
---|
| 96 | $archive_dir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "archives")
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | # BACKWARDS COMPATIBILITY: Just in case there are old .ldb/.bdb files (won't do anything for other infodbtypes)
|
---|
| 100 | &util::rename_ldb_or_bdb_file(&util::filename_cat($archive_dir, "archiveinf-doc"));
|
---|
| 101 |
|
---|
| 102 | my $archiveinf_doc = &dbutil::get_infodb_file_path("gdbm", "archiveinf-doc", $archive_dir);
|
---|
| 103 |
|
---|
| 104 | my $quoted_argv = join(" ", map { "\"$_\"" } @filtered_argv);
|
---|
| 105 |
|
---|
| 106 | # need to ensure that the path to perl is quoted (in case there's spaces in it)
|
---|
[24362] | 107 | my $import_cmd = "\"".&util::get_perl_exec()."\" -S import.pl";
|
---|
[21861] | 108 |
|
---|
| 109 | if (-e $archiveinf_doc) {
|
---|
[24362] | 110 | $import_cmd .= " -keepold";
|
---|
[21861] | 111 | }
|
---|
| 112 | else {
|
---|
| 113 | print STDERR "*****\n";
|
---|
| 114 | print STDERR "First time import. Switching to full import.pl.\n";
|
---|
| 115 | print STDERR "*****\n";
|
---|
| 116 | $import_cmd .= " -removeold";
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | $import_cmd .= " $quoted_argv \"$collection\"";
|
---|
| 120 |
|
---|
| 121 | my $import_status = system($import_cmd)/256;
|
---|
| 122 |
|
---|
| 123 | if ($import_status != 0) {
|
---|
| 124 | print STDERR "Error: Failed to run: $import_cmd\n";
|
---|
| 125 | print STDERR " $!\n" if ($! ne "");
|
---|
| 126 | exit(-1);
|
---|
| 127 | }
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | &main(scalar(@ARGV),@ARGV);
|
---|