root/trunk/gsdl/bin/script/import.pl @ 848

Revision 848, 6.0 KB (checked in by sjboddie, 20 years ago)

added use strict

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1#!/usr/local/bin/perl5 -w
2
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
29# This program will import a number of files into a particular collection
30
31BEGIN {
32    die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
33    die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
34    unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
35    unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugins");
36}
37
38use strict;
39use arcinfo;
40use colcfg;
41use plugin;
42use docprint;
43use util;
44use parsargv;
45
46sub print_usage {
47    print STDERR "\n  usage: $0 [options] collection-name\n\n";
48    print STDERR "  options:\n";
49    print STDERR "   -verbosity number      0=none, 3=lots\n";
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";
55    print STDERR "                          directory -- use with care\n";
56    print STDERR "   -gzip                  Use gzip to compress resulting gml documents\n";
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";
60}
61
62
63&main ();
64
65sub main {
66    my ($verbosity, $importdir, $archivedir, $keepold,
67    $removeold, $gzip, $groupsize, $debug, $maxdocs, $collection,
68    $configfilename, $collectcfg, $pluginfo,
69    $archive_info_filename, $archive_info, $processor);
70    if (!parsargv::parse(\@ARGV,
71             'verbosity/\d+/2', \$verbosity,
72             'importdir/.*/', \$importdir,
73             'archivedir/.*/', \$archivedir,
74             'keepold', \$keepold,
75             'removeold', \$removeold,
76             'gzip', \$gzip,
77             'groupsize/\d+/1', \$groupsize,
78             'debug', \$debug,
79             'maxdocs/^\-?\d+/-1', \$maxdocs)) {
80    &print_usage();
81    die "\n";
82    }
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();
90    die "\n";
91    }
92
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
100    # get the list of plugins for this collection
101    my $plugins = [];
102    $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc/collect.cfg");
103    if (-e $configfilename) {
104    $collectcfg = &colcfg::read_collect_cfg ($configfilename);
105    if (defined $collectcfg->{'plugin'}) {
106        $plugins = $collectcfg->{'plugin'};
107    }
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    }
122    } else {
123    die "Couldn't find the configuration file $configfilename\n";
124    }
125   
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/\/$//;
134
135    # load all the plugins
136    $pluginfo = &plugin::load_plugins ($plugins);
137    if (scalar(@$pluginfo) == 0) {
138    print STDERR "No plugins were loaded.\n";
139    die "\n";
140    }
141   
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    }
149   
150    # read the archive information file
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);
155
156    # create a docsave object to process the documents
157    $processor = new docsave ($collection, $archive_info, $verbosity, $gzip, $groupsize);
158    $processor->setarchivedir ($archivedir);
159    } else {
160    $processor = new docprint ();
161    }
162
163    &plugin::begin($pluginfo, $importdir, $processor, $maxdocs);
164
165    # process the import directory
166    &plugin::read ($pluginfo, $importdir, "", {}, $processor, $maxdocs);
167   
168    &plugin::end($pluginfo);
169
170    $processor->close_file_output();
171
172    # write out the archive information file
173    if (!$debug) {
174    $archive_info->save_info($archive_info_filename);
175    }
176}
177
178
179
180
181
Note: See TracBrowser for help on using the browser.