source: trunk/gsdl/bin/script/import.pl@ 946

Last change on this file since 946 was 946, checked in by sjboddie, 24 years ago

Fixed bug - classify directory was not included in @INC

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