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

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

removed obsolete 'key' field

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
Line 
1#!/usr/local/bin/perl5 -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
33BEGIN {
34 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
35 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
36}
37
38use parsargv;
39
40sub print_usage {
41 print STDERR "\n usage: $0 [options] collection-name\n\n";
42 print STDERR " options:\n";
43 print STDERR " -creator email Your email address\n";
44 print STDERR " -maintainer email The current maintainer's email address\n";
45 print STDERR " -public true|false If this collection has anonymous access\n";
46 print STDERR " -beta true|false If this collection is still under development\n";
47# print STDERR " -index type The indexes which should be made\n";
48# print STDERR " -indextext name The index description\n";
49# print STDERR " -defaultindex type The index to use if no others are supplied\n\n";
50}
51
52sub traverse_dir
53{
54 my ($modeldir, $coldir) = @_;
55 my ($newfile, @filetext);
56
57 if (!(-e $coldir)) {
58 if (!mkdir ($coldir, 0775)) {
59 die "$!";
60 }
61 }
62
63 opendir(DIR, $modeldir) || die "Can't read $modeldir";
64 my @files = grep(!/^(\.\.?|CVS)$/, readdir(DIR));
65 closedir(DIR);
66
67 foreach $file (@files)
68 {
69 if (-d "$modeldir/$file") {
70 traverse_dir ("$modeldir/$file", "$coldir/$file");
71
72 } else {
73 my $destfile = $file;
74 $destfile =~ s/^\modelcol/$collection/;
75 $destfile =~ s/^\MODELCOL/$capcollection/;
76
77 print STDERR "doing replacements for $modeldir/$file\n";
78 open (INFILE, "$modeldir/$file") ||
79 die "Can't read file $modeldir/$file";
80 open (OUTFILE, ">$coldir/$destfile") ||
81 die "Can't create file $coldir/destfile";
82
83 while (defined ($line = <INFILE>)) {
84 $line =~ s/\*\*collection\*\*/$collection/g;
85 $line =~ s/\*\*COLLECTION\*\*/$capcollection/g;
86 $line =~ s/\*\*creator\*\*/$creator/g;
87 $line =~ s/\*\*maintainer\*\*/$maintainer/g;
88 $line =~ s/\*\*public\*\*/$public/g;
89 $line =~ s/\*\*beta\*\*/$beta/g;
90 $line =~ s/\*\*indexes\*\*/$indexesstr/g;
91 $line =~ s/\*\*indexestext\*\*/$indexestextstr/g;
92 $line =~ s/\*\*defaultindex\*\*/$defaultindex/g;
93
94 print OUTFILE $line;
95 }
96
97 close (OUTFILE);
98 close (INFILE);
99 }
100 }
101}
102
103
104my (@indexes, @indexestext);
105
106# get and check options
107if (!&parsargv::parse(\@ARGV,
108 'creator/\w+\@[\w\.]+/', \$creator,
109 'maintainer/\w+\@[\w\.]+/', \$maintainer,
110 'public/true|false/true', \$public,
111 'beta/true|false/true', \$beta,
112 'index/.*/document:all', \@indexes,
113 'indextext/\.*/Terms must appear within the same document', \@indexestext,
114 'defaultindex/.*/document:all', \$defaultindex
115 )) {
116 &print_usage();
117 die "\n";
118}
119
120# get and check the collection name
121($collection) = @ARGV;
122if (!defined($collection)) {
123 &print_usage();
124 die "\n";
125}
126
127if (length($collection) > 8) {
128 print STDERR "The collection name must be less than 8 characters\n";
129 print STDERR "so compatibility with earlier filesystems can be\n";
130 print STDERR "maintained.\n";
131 die "\n";
132}
133
134if ($collection eq "modelcol") {
135 print STDERR "No collection can be named modelcol as this is the\n";
136 print STDERR "name of the model collection.\n";
137 die "\n";
138}
139
140if ($collection eq "CVS") {
141 print STDERR "No collection can be named CVS as this may interfere\n";
142 print STDERR "with directories created by the CVS versioning system\n";
143 die "\n";
144}
145
146if (!defined($creator) || $creator eq "") {
147 print STDERR "The creator was not defined. This variable is\n";
148 print STDERR "needed to recognise duplicate collection names.\n";
149 die "\n";
150}
151
152if (!defined($maintainer) || $maintainer eq "") {
153 $maintainer = $creator;
154}
155
156$public = "true" unless defined $public;
157$beta = "true" unless defined $beta;
158
159# get capitalised version of the collection
160$capcollection = $collection;
161$capcollection =~ tr/a-z/A-Z/;
162
163
164# get the strings to include.
165$indexesstr = join ("\t", @indexes);
166$indexestextstr = "";
167for ($i=0; $i<scalar(@indexestext); $i++) {
168 $indexestextstr .= "_$indexes[$i]_[] {$indexestext[$i]}\n";
169}
170
171
172# make sure the model collection exists
173die "Cannot find the model collection $ENV{'GSDLHOME'}/collect/modelcol" unless
174 (-d "$ENV{'GSDLHOME'}/collect/modelcol");
175
176# make sure this collection does not already exist
177if (-e "$ENV{'GSDLHOME'}/collect/$collection") {
178 print STDERR "This collection already exists\n";
179 die "\n";
180}
181
182
183# start creating the collection
184print STDERR "Creating the collection $collection\n\n";
185&traverse_dir ("$ENV{'GSDLHOME'}/collect/modelcol", "$ENV{'GSDLHOME'}/collect/$collection");
186print STDERR "\n\nThe new collection is in $ENV{'GSDLHOME'}/collect/$collection.\n\n";
187
Note: See TracBrowser for help on using the repository browser.