source: trunk/gsdl/bin/script/mkcol.pl@ 1587

Last change on this file since 1587 was 1454, checked in by stefan, 24 years ago

Lots of changes to perl building code for collectoraction

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 8.1 KB
Line 
1#!/usr/bin/perl -w
2
3###########################################################################
4#
5# mkcol.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 setup a new collection from a model one. It does this by
30# copying the model, moving files to have the correct names, and replacing
31# text within the files to match the parameters.
32
33package mkcol;
34
35BEGIN {
36 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
37 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
38}
39
40use parsargv;
41use util;
42use cfgread;
43
44sub print_usage {
45 print STDERR "\n usage: $0 [options] collection-name\n\n";
46 print STDERR " options:\n";
47 print STDERR " -optionfile file Get options from file, useful on systems where\n";
48 print STDERR " long command lines may cause problems\n";
49 print STDERR " -collectdir Collection to create new collection in.\n";
50 print STDERR " Default is " .
51 &util::filename_cat($ENV{'GSDLHOME'}, "collect") . "\n";
52 print STDERR " -creator email Your email address\n";
53 print STDERR " -maintainer email The current maintainer's email address\n";
54 print STDERR " -public true|false If this collection has anonymous access\n";
55 print STDERR " -beta true|false If this collection is still under development\n";
56# print STDERR " -index type The indexes which should be made\n";
57# print STDERR " -indextext name The index description\n";
58# print STDERR " -defaultindex type The index to use if no others are supplied\n";
59
60 print STDERR " -title text The title for the collection\n";
61 print STDERR " -about text The about text for the collection\n";
62 print STDERR " -plugin text perl plugin module to use (there may be multiple\n";
63 print STDERR " plugin entries\n";
64 print STDERR " -refine list Space separated list of perl plugin modules to use\n";
65
66
67}
68
69sub traverse_dir
70{
71 my ($modeldir, $coldir) = @_;
72 my ($newfile, @filetext);
73
74 if (!(-e $coldir)) {
75
76 my $store_umask = umask(0002);
77 my $mkdir_ok = mkdir ($coldir, 0777);
78 umask($store_umask);
79
80 if (!$mkdir_ok)
81 {
82 die "$!";
83 }
84 }
85
86 opendir(DIR, $modeldir) || die "Can't read $modeldir";
87 my @files = grep(!/^(\.\.?|CVS)$/, readdir(DIR));
88 closedir(DIR);
89
90 foreach $file (@files)
91 {
92 my $thisfile = &util::filename_cat ($modeldir, $file);
93 if (-d $thisfile) {
94 my $colfiledir = &util::filename_cat ($coldir, $file);
95 traverse_dir ($thisfile, $colfiledir);
96
97 } else {
98 my $destfile = $file;
99 $destfile =~ s/^modelcol/$collection/;
100 $destfile =~ s/^MODELCOL/$capcollection/;
101 $destfile = &util::filename_cat ($coldir, $destfile);
102
103 print STDERR "doing replacements for $thisfile\n";
104 open (INFILE, $thisfile) ||
105 die "Can't read file $thisfile";
106 open (OUTFILE, ">$destfile") ||
107 die "Can't create file $destfile";
108
109 while (defined ($line = <INFILE>)) {
110 $line =~ s/\*\*collection\*\*/$collection/g;
111 $line =~ s/\*\*COLLECTION\*\*/$capcollection/g;
112 $line =~ s/\*\*creator\*\*/$creator/g;
113 $line =~ s/\*\*maintainer\*\*/$maintainer/g;
114 $line =~ s/\*\*public\*\*/$public/g;
115 $line =~ s/\*\*beta\*\*/$beta/g;
116 $line =~ s/\*\*indexes\*\*/$indexesstr/g;
117 $line =~ s/\*\*indexestext\*\*/$indexestextstr/g;
118 $line =~ s/\*\*defaultindex\*\*/$defaultindex/g;
119 $line =~ s/\*\*title\*\*/$title/g;
120 $line =~ s/\*\*about\*\*/$about/g;
121 $line =~ s/\*\*plugins\*\*/$pluginstring/g;
122 $line =~ s/\*\*refine\*\*/$refine/g;
123
124 print OUTFILE $line;
125 }
126
127 close (OUTFILE);
128 close (INFILE);
129 }
130 }
131}
132
133# get and check options
134sub parse_args {
135 my ($argref) = @_;
136 if (!&parsargv::parse($argref,
137 'optionfile/.*/', \$optionfile,
138 'collectdir/.*/', \$collectdir,
139 'creator/\w+\@[\w\.]+/', \$creator,
140 'maintainer/\w+\@[\w\.]+/', \$maintainer,
141 'public/true|false/true', \$public,
142 'beta/true|false/true', \$beta,
143 'index/.*/document:all', \@indexes,
144 'indextext/\.*/Terms must appear within the same document', \@indexestext,
145 'defaultindex/.*/document:all', \$defaultindex,
146 'title/.+/', \$title,
147 'about/.+/', \$about,
148 'plugin/.+', \@plugin,
149 'refine/.+/', \$refine
150 )) {
151 &print_usage();
152 die "\n";
153 }
154}
155
156sub main {
157
158 &parse_args (\@ARGV);
159 if ($optionfile =~ /\w/) {
160 open (OPTIONS, $optionfile) || die "Couldn't open $optionfile\n";
161 my $line = [];
162 my $options = [];
163 while (defined ($line = &cfgread::read_cfg_line ('mkcol::OPTIONS'))) {
164 push (@$options, @$line);
165 }
166 close OPTIONS;
167 &parse_args ($options);
168
169 }
170
171 # load default plugins if none were on command line
172 if (!scalar(@plugin)) {
173 @plugin = (ZIPPlug,GMLPlug,TEXTPlug,HTMLPlug,EMAILPlug,ArcPlug,RecPlug);
174 }
175
176 # get and check the collection name
177 ($collection) = @ARGV;
178 if (!defined($collection)) {
179 print STDERR "no collection name was specified\n";
180 &print_usage();
181 die "\n";
182 }
183
184 if (length($collection) > 8) {
185 print STDERR "The collection name must be less than 8 characters\n";
186 print STDERR "so compatibility with earlier filesystems can be\n";
187 print STDERR "maintained.\n";
188 die "\n";
189 }
190
191 if ($collection eq "modelcol") {
192 print STDERR "No collection can be named modelcol as this is the\n";
193 print STDERR "name of the model collection.\n";
194 die "\n";
195 }
196
197 if ($collection eq "CVS") {
198 print STDERR "No collection can be named CVS as this may interfere\n";
199 print STDERR "with directories created by the CVS versioning system\n";
200 die "\n";
201 }
202
203 if (!defined($creator) || $creator eq "") {
204 print STDERR "The creator was not defined. This variable is\n";
205 print STDERR "needed to recognise duplicate collection names.\n";
206 die "\n";
207 }
208
209 if (!defined($maintainer) || $maintainer eq "") {
210 $maintainer = $creator;
211 }
212
213 $public = "true" unless defined $public;
214 $beta = "true" unless defined $beta;
215
216 if (!defined($title) || $title eq "") {
217 $title = $collection;
218 }
219
220 # get capitalised version of the collection
221 $capcollection = $collection;
222 $capcollection =~ tr/a-z/A-Z/;
223
224 # get the strings to include.
225 $indexesstr = join ("\t", @indexes);
226 $indexestextstr = "";
227 for ($i=0; $i<scalar(@indexestext); $i++) {
228 $indexestextstr .= "_$indexes[$i]_[] {$indexestext[$i]}\n";
229 }
230
231 $pluginstring = "";
232 foreach $plugin (@plugin) {
233 $pluginstring .= "plugin $plugin\n";
234 }
235
236 $mdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", "modelcol");
237 if (defined $collectdir && $collectdir =~ /\w/) {
238 if (!-d $collectdir) {
239 print STDERR "ERROR: $collectdir doesn't exist\n";
240 die "\n";
241 }
242 $cdir = &util::filename_cat ($collectdir, $collection);
243 } else {
244 $cdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collection);
245 }
246
247 # make sure the model collection exists
248 die "Cannot find the model collection $mdir" unless (-d $mdir);
249
250 # make sure this collection does not already exist
251 if (-e $cdir) {
252 print STDERR "This collection already exists\n";
253 die "\n";
254 }
255
256 # start creating the collection
257 print STDERR "Creating the collection $collection\n";
258 &traverse_dir ($mdir, $cdir);
259 print STDERR "The new collection is in $cdir.\n";
260}
261
262&main ();
Note: See TracBrowser for help on using the repository browser.