[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 |
|
---|
[18491] | 43 | use util;
|
---|
[18470] | 44 |
|
---|
| 45 |
|
---|
[18491] | 46 | sub main
|
---|
| 47 | {
|
---|
| 48 | my ($argc,@argv) = @_;
|
---|
[18470] | 49 |
|
---|
[18491] | 50 | if (($argc==0) || (($argc==1) && ($argv[0] =~ m/^--?h(elp)?$/))) {
|
---|
| 51 | my ($progname) = ($0 =~ m/^.*\/(.*?)$/);
|
---|
[18470] | 52 |
|
---|
[18491] | 53 |
|
---|
| 54 | print STDERR "\n";
|
---|
| 55 | print STDERR "Usage: $progname [import.pl options] collection\n";
|
---|
| 56 | print STDERR "\n";
|
---|
| 57 |
|
---|
| 58 | exit(-1);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 |
|
---|
| 62 | my $collect = pop @argv;
|
---|
| 63 |
|
---|
| 64 | my @filtered_argv = ();
|
---|
| 65 |
|
---|
| 66 | my $collect_dir = undef;
|
---|
| 67 | my $archive_dir = undef;
|
---|
| 68 |
|
---|
| 69 | while (my $arg = shift @argv) {
|
---|
| 70 | # No actual filtering happens at the moment (@filterd_argv == @argv)
|
---|
| 71 | # Useful to do it this way if we want incremental-import.pl
|
---|
| 72 | # to start accepting its own arguments that are different to import.pl
|
---|
| 73 |
|
---|
| 74 | if ($arg eq "-collectdir") {
|
---|
| 75 | $collect_dir = shift @argv;
|
---|
| 76 | push(@filtered_argv,$arg,$collect_dir);
|
---|
| 77 | }
|
---|
| 78 | elsif ($arg eq "-archivedir") {
|
---|
| 79 | $archive_dir = shift @argv;
|
---|
| 80 | push(@filtered_argv,$arg,$archive_dir);
|
---|
| 81 | }
|
---|
| 82 | else {
|
---|
| 83 | push(@filtered_argv,$arg);
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | if (!defined $collect_dir) {
|
---|
[18510] | 88 | $collect_dir = &util::filename_cat($ENV{'GSDLHOME'},"collect");
|
---|
[18491] | 89 | }
|
---|
[18510] | 90 | my $this_collect_dir = &util::filename_cat($collect_dir,$collect);
|
---|
| 91 |
|
---|
| 92 | if (!-d $this_collect_dir) {
|
---|
| 93 | print STDERR "Error: $this_collect_dir does not exist\n";
|
---|
[18491] | 94 | exit(-1);
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 |
|
---|
| 98 | if (!defined $archive_dir) {
|
---|
[18510] | 99 | $archive_dir = &util::filename_cat($this_collect_dir,"archives");
|
---|
[18491] | 100 | }
|
---|
| 101 |
|
---|
[18660] | 102 | my $archiveinf_doc = &util::filename_cat($archive_dir,"archiveinf-doc");
|
---|
| 103 | &util::rename_gdbm_file($archiveinf_doc); # ensure gdb
|
---|
| 104 | $archiveinf_doc .= ".gdb";
|
---|
[18491] | 105 | my $quoted_argv = join(" ", map { "\"$_\"" } @filtered_argv);
|
---|
| 106 |
|
---|
| 107 |
|
---|
| 108 | my $import_cmd = "import.pl";
|
---|
| 109 | if (-e $archiveinf_doc) {
|
---|
| 110 | $import_cmd .= " -incremental";
|
---|
| 111 |
|
---|
| 112 | }
|
---|
| 113 | else {
|
---|
[18492] | 114 | ### print STDERR "$archiveinf_doc does not exist.\n";
|
---|
| 115 | print STDERR "*****\n";
|
---|
[18491] | 116 | print STDERR "First time built. Switching to full import.pl.\n";
|
---|
[18492] | 117 | print STDERR "*****\n";
|
---|
[18491] | 118 | $import_cmd .= " -removeold";
|
---|
| 119 | }
|
---|
| 120 |
|
---|
[18492] | 121 | $import_cmd .= " $quoted_argv \"$collect\"";
|
---|
[18491] | 122 |
|
---|
[18492] | 123 |
|
---|
[18491] | 124 | my $import_status = system($import_cmd)/256;
|
---|
| 125 |
|
---|
| 126 | if ($import_status != 0) {
|
---|
| 127 | print STDERR "Error: Failed to run: $import_cmd\n";
|
---|
| 128 | print STDERR " $!\n" if ($! ne "");
|
---|
| 129 | exit(-1);
|
---|
| 130 | }
|
---|
[18470] | 131 | }
|
---|
| 132 |
|
---|
[18491] | 133 | &main(scalar(@ARGV),@ARGV);
|
---|