[4] | 1 | #!/usr/local/bin/perl5 -w
|
---|
| 2 |
|
---|
[538] | 3 | ###########################################################################
|
---|
| 4 | #
|
---|
| 5 | # import.pl --
|
---|
| 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) 1999 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 |
|
---|
[4] | 29 | # This program will import a number of files into a particular collection
|
---|
| 30 |
|
---|
| 31 | BEGIN {
|
---|
| 32 | die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
|
---|
| 33 | die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
|
---|
[9] | 34 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
|
---|
| 35 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugins");
|
---|
[4] | 36 | }
|
---|
| 37 |
|
---|
[848] | 38 | use strict;
|
---|
[4] | 39 | use arcinfo;
|
---|
| 40 | use colcfg;
|
---|
| 41 | use plugin;
|
---|
[783] | 42 | use docprint;
|
---|
[130] | 43 | use util;
|
---|
| 44 | use parsargv;
|
---|
[4] | 45 |
|
---|
| 46 | sub print_usage {
|
---|
[130] | 47 | print STDERR "\n usage: $0 [options] collection-name\n\n";
|
---|
| 48 | print STDERR " options:\n";
|
---|
[169] | 49 | print STDERR " -verbosity number 0=none, 3=lots\n";
|
---|
[130] | 50 | print STDERR " -importdir directory Where the original material lives\n";
|
---|
| 51 | print STDERR " -archivedir directory Where the converted material ends up\n";
|
---|
| 52 | print STDERR " -keepold Will not destroy the current contents of the\n";
|
---|
| 53 | print STDERR " archives directory (the default)\n";
|
---|
| 54 | print STDERR " -removeold Will remove the old contents of the archives\n";
|
---|
[314] | 55 | print STDERR " directory -- use with care\n";
|
---|
[433] | 56 | print STDERR " -gzip Use gzip to compress resulting gml documents\n";
|
---|
[843] | 57 | print STDERR " -maxdocs number Maximum number of documents to import\n";
|
---|
| 58 | print STDERR " -groupsize number Number of GML documents to group into one file\n";
|
---|
| 59 | print STDERR " -debug Print imported text to STDOUT\n\n";
|
---|
[4] | 60 | }
|
---|
| 61 |
|
---|
| 62 |
|
---|
| 63 | &main ();
|
---|
| 64 |
|
---|
| 65 | sub main {
|
---|
[783] | 66 | my ($verbosity, $importdir, $archivedir, $keepold,
|
---|
[848] | 67 | $removeold, $gzip, $groupsize, $debug, $maxdocs, $collection,
|
---|
| 68 | $configfilename, $collectcfg, $pluginfo,
|
---|
| 69 | $archive_info_filename, $archive_info, $processor);
|
---|
[130] | 70 | if (!parsargv::parse(\@ARGV,
|
---|
[169] | 71 | 'verbosity/\d+/2', \$verbosity,
|
---|
[130] | 72 | 'importdir/.*/', \$importdir,
|
---|
| 73 | 'archivedir/.*/', \$archivedir,
|
---|
| 74 | 'keepold', \$keepold,
|
---|
[314] | 75 | 'removeold', \$removeold,
|
---|
[433] | 76 | 'gzip', \$gzip,
|
---|
[843] | 77 | 'groupsize/\d+/1', \$groupsize,
|
---|
[783] | 78 | 'debug', \$debug,
|
---|
[814] | 79 | 'maxdocs/^\-?\d+/-1', \$maxdocs)) {
|
---|
[4] | 80 | &print_usage();
|
---|
| 81 | die "\n";
|
---|
| 82 | }
|
---|
[130] | 83 |
|
---|
| 84 | # set removeold to false if it has been defined
|
---|
| 85 | $removeold = 0 if ($keepold);
|
---|
| 86 |
|
---|
| 87 | # get and check the collection name
|
---|
| 88 | if (($collection = &util::use_collection(@ARGV)) eq "") {
|
---|
| 89 | &print_usage();
|
---|
[4] | 90 | die "\n";
|
---|
| 91 | }
|
---|
[130] | 92 |
|
---|
[843] | 93 | # dynamically load 'docsave' module so it can pick up on a collection
|
---|
| 94 | # specific docsave.pm is specified.
|
---|
| 95 |
|
---|
| 96 | unshift (@INC, "$ENV{'GSDLCOLLECTDIR'}/perllib");
|
---|
| 97 | require docsave;
|
---|
| 98 |
|
---|
| 99 |
|
---|
[4] | 100 | # get the list of plugins for this collection
|
---|
[814] | 101 | my $plugins = [];
|
---|
[130] | 102 | $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc/collect.cfg");
|
---|
| 103 | if (-e $configfilename) {
|
---|
| 104 | $collectcfg = &colcfg::read_collect_cfg ($configfilename);
|
---|
[814] | 105 | if (defined $collectcfg->{'plugin'}) {
|
---|
| 106 | $plugins = $collectcfg->{'plugin'};
|
---|
[4] | 107 | }
|
---|
[130] | 108 | if (defined $collectcfg->{'importdir'} && $importdir eq "") {
|
---|
| 109 | $importdir = $collectcfg->{'importdir'};
|
---|
| 110 | }
|
---|
| 111 | if (defined $collectcfg->{'archivedir'} && $archivedir eq "") {
|
---|
| 112 | $archivedir = $collectcfg->{'archivedir'};
|
---|
| 113 | }
|
---|
| 114 | if (defined $collectcfg->{'removeold'}) {
|
---|
| 115 | if ($collectcfg->{'removeold'} =~ /^true$/i && !$keepold) {
|
---|
| 116 | $removeold = 1;
|
---|
| 117 | }
|
---|
| 118 | if ($collectcfg->{'removeold'} =~ /^false$/i && !$removeold) {
|
---|
| 119 | $removeold = 0;
|
---|
| 120 | }
|
---|
| 121 | }
|
---|
[98] | 122 | } else {
|
---|
[130] | 123 | die "Couldn't find the configuration file $configfilename\n";
|
---|
[4] | 124 | }
|
---|
| 125 |
|
---|
[130] | 126 | # fill in the default import and archives directories if none
|
---|
| 127 | # were supplied, turn all \ into / and remove trailing /
|
---|
| 128 | $importdir = "$ENV{'GSDLCOLLECTDIR'}/import" if $importdir eq "";
|
---|
| 129 | $importdir =~ s/[\\\/]+/\//g;
|
---|
| 130 | $importdir =~ s/\/$//;
|
---|
| 131 | $archivedir = "$ENV{'GSDLCOLLECTDIR'}/archives" if $archivedir eq "";
|
---|
| 132 | $archivedir =~ s/[\\\/]+/\//g;
|
---|
| 133 | $archivedir =~ s/\/$//;
|
---|
[4] | 134 |
|
---|
| 135 | # load all the plugins
|
---|
[814] | 136 | $pluginfo = &plugin::load_plugins ($plugins);
|
---|
[4] | 137 | if (scalar(@$pluginfo) == 0) {
|
---|
| 138 | print STDERR "No plugins were loaded.\n";
|
---|
| 139 | die "\n";
|
---|
| 140 | }
|
---|
[843] | 141 |
|
---|
[130] | 142 | # remove the old contents of the archives directory if needed
|
---|
| 143 | if ($removeold && -e $archivedir) {
|
---|
| 144 | print STDERR "Warning - removing current contents of the archives directory\n";
|
---|
| 145 | print STDERR " in preparation for the import\n";
|
---|
| 146 | sleep(5); # just in case...
|
---|
| 147 | &util::rm_r ($archivedir);
|
---|
| 148 | }
|
---|
[843] | 149 |
|
---|
[4] | 150 | # read the archive information file
|
---|
[783] | 151 | if (!$debug) {
|
---|
| 152 | $archive_info_filename = &util::filename_cat ($archivedir, "archives.inf");
|
---|
| 153 | $archive_info = new arcinfo ();
|
---|
| 154 | $archive_info->load_info ($archive_info_filename);
|
---|
[4] | 155 |
|
---|
[783] | 156 | # create a docsave object to process the documents
|
---|
[843] | 157 | $processor = new docsave ($collection, $archive_info, $verbosity, $gzip, $groupsize);
|
---|
[783] | 158 | $processor->setarchivedir ($archivedir);
|
---|
| 159 | } else {
|
---|
| 160 | $processor = new docprint ();
|
---|
| 161 | }
|
---|
[4] | 162 |
|
---|
[843] | 163 | &plugin::begin($pluginfo, $importdir, $processor, $maxdocs);
|
---|
| 164 |
|
---|
[4] | 165 | # process the import directory
|
---|
[843] | 166 | &plugin::read ($pluginfo, $importdir, "", {}, $processor, $maxdocs);
|
---|
[4] | 167 |
|
---|
[843] | 168 | &plugin::end($pluginfo);
|
---|
[896] | 169 |
|
---|
[4] | 170 | # write out the archive information file
|
---|
[783] | 171 | if (!$debug) {
|
---|
[896] | 172 | $processor->close_file_output();
|
---|
[783] | 173 | $archive_info->save_info($archive_info_filename);
|
---|
| 174 | }
|
---|
[4] | 175 | }
|
---|
[843] | 176 |
|
---|
| 177 |
|
---|
| 178 |
|
---|
| 179 |
|
---|
| 180 |
|
---|