source: main/trunk/greenstone2/bin/script/incremental-import.pl@ 21732

Last change on this file since 21732 was 21732, checked in by kjdon, 14 years ago

archivedir should be archive_dir

  • Property svn:executable set to *
File size: 4.1 KB
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
33
34BEGIN {
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
41use strict;
42
43use dbutil;
44use util;
45
46
47sub main
48{
49 my ($argc,@argv) = @_;
50
51 if (($argc==0) || (($argc==1) && ($argv[0] =~ m/^--?h(elp)?$/))) {
52 my ($progname) = ($0 =~ m/^.*[\/|\\](.*?)$/);
53
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
63 my $collect = pop @argv;
64
65 my @filtered_argv = ();
66
67 my $collect_dir = undef;
68 my $archive_dir = undef;
69
70 while (my $arg = shift @argv) {
71 # No actual filtering happens at the moment (@filterd_argv == @argv)
72 # Useful to do it this way if we want incremental-import.pl
73 # to start accepting its own arguments that are different to import.pl
74
75 if ($arg eq "-collectdir") {
76 $collect_dir = shift @argv;
77 push(@filtered_argv,$arg,$collect_dir);
78 }
79 elsif ($arg eq "-archivedir") {
80 $archive_dir = shift @argv;
81 push(@filtered_argv,$arg,$archive_dir);
82 }
83 else {
84 push(@filtered_argv,$arg);
85 }
86 }
87
88 if (!defined $collect_dir) {
89 $collect_dir = &util::filename_cat($ENV{'GSDLHOME'},"collect");
90 }
91 my $this_collect_dir = &util::filename_cat($collect_dir,$collect);
92
93 if (!-d $this_collect_dir) {
94 print STDERR "Error: $this_collect_dir does not exist\n";
95 exit(-1);
96 }
97
98
99 if (!defined $archive_dir) {
100 $archive_dir = &util::filename_cat($this_collect_dir,"archives");
101 }
102
103 # BACKWARDS COMPATIBILITY: Just in case there are old .ldb/.bdb files (won't do anything for other infodbtypes)
104 &util::rename_ldb_or_bdb_file(&util::filename_cat($archive_dir, "archiveinf-doc"));
105
106 my $archiveinf_doc = &dbutil::get_infodb_file_path("gdbm", "archiveinf-doc", $archive_dir);
107
108 my $quoted_argv = join(" ", map { "\"$_\"" } @filtered_argv);
109
110
111 my $import_cmd = "import.pl";
112 if($ENV{'PERLPATH'}) {
113 # need to ensure that the path to perl is quoted (in case there's spaces in it)
114 if($ENV{'GSDLOS'} =~ m/windows/) {
115 $import_cmd = "\"$ENV{'PERLPATH'}\\Perl.exe\" -S $import_cmd";
116 } else {
117 $import_cmd = "\"$ENV{'PERLPATH'}/perl\" -S $import_cmd";
118 }
119 } else {
120 $import_cmd = "perl -S $import_cmd";
121 }
122
123 if (-e $archiveinf_doc) {
124 $import_cmd .= " -incremental";
125
126 }
127 else {
128 print STDERR "*****\n";
129 print STDERR "First time import. Switching to full import.pl.\n";
130 print STDERR "*****\n";
131 $import_cmd .= " -removeold";
132 }
133
134 $import_cmd .= " $quoted_argv \"$collect\"";
135
136
137 my $import_status = system($import_cmd)/256;
138
139 if ($import_status != 0) {
140 print STDERR "Error: Failed to run: $import_cmd\n";
141 print STDERR " $!\n" if ($! ne "");
142 exit(-1);
143 }
144}
145
146&main(scalar(@ARGV),@ARGV);
Note: See TracBrowser for help on using the repository browser.