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

Last change on this file since 581 was 581, checked in by sjboddie, 25 years ago

removed index, indextext and defaultindex options for now

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 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/\*\*key\*\*/$key/g;
91 $line =~ s/\*\*indexes\*\*/$indexesstr/g;
92 $line =~ s/\*\*indexestext\*\*/$indexestextstr/g;
93 $line =~ s/\*\*defaultindex\*\*/$defaultindex/g;
94
95 print OUTFILE $line;
96 }
97
98 close (OUTFILE);
99 close (INFILE);
100 }
101 }
102}
103
104
105my (@indexes, @indexestext);
106
107# get and check options
108if (!&parsargv::parse(\@ARGV,
109 'creator/\w+\@[\w\.]+/', \$creator,
110 'maintainer/\w+\@[\w\.]+/', \$maintainer,
111 'public/true|false/true', \$public,
112 'beta/true|false/true', \$beta,
113 'index/.*/document:all', \@indexes,
114 'indextext/\.*/Terms must appear within the same document', \@indexestext,
115 'defaultindex/.*/document:all', \$defaultindex
116 )) {
117 &print_usage();
118 die "\n";
119}
120
121# get and check the collection name
122($collection) = @ARGV;
123if (!defined($collection)) {
124 &print_usage();
125 die "\n";
126}
127
128if (length($collection) > 8) {
129 print STDERR "The collection name must be less than 8 characters\n";
130 print STDERR "so compatibility with earlier filesystems can be\n";
131 print STDERR "maintained.\n";
132 die "\n";
133}
134
135if ($collection eq "modelcol") {
136 print STDERR "No collection can be named modelcol as this is the\n";
137 print STDERR "name of the model collection.\n";
138 die "\n";
139}
140
141if ($collection eq "CVS") {
142 print STDERR "No collection can be named CVS as this may interfere\n";
143 print STDERR "with directories created by the CVS versioning system\n";
144 die "\n";
145}
146
147if (!defined($creator) || $creator eq "") {
148 print STDERR "The creator was not defined. This variable is\n";
149 print STDERR "needed to recognise duplicate collection names.\n";
150 die "\n";
151}
152
153if (!defined($maintainer) || $maintainer eq "") {
154 $maintainer = $creator;
155}
156
157$public = "true" unless defined $public;
158$beta = "true" unless defined $beta;
159
160srand(time);
161$key = int(rand()*100000000.0) + int(rand()*100000000.0);
162
163# get capitalised version of the collection
164$capcollection = $collection;
165$capcollection =~ tr/a-z/A-Z/;
166
167
168# get the strings to include.
169$indexesstr = join ("\t", @indexes);
170$indexestextstr = "";
171for ($i=0; $i<scalar(@indexestext); $i++) {
172 $indexestextstr .= "_$indexes[$i]_[] {$indexestext[$i]}\n";
173}
174
175
176# make sure the model collection exists
177die "Cannot find the model collection $ENV{'GSDLHOME'}/collect/modelcol" unless
178 (-d "$ENV{'GSDLHOME'}/collect/modelcol");
179
180# make sure this collection does not already exist
181if (-e "$ENV{'GSDLHOME'}/collect/$collection") {
182 print STDERR "This collection already exists\n";
183 die "\n";
184}
185
186
187# start creating the collection
188print STDERR "Creating the collection $collection\n\n";
189&traverse_dir ("$ENV{'GSDLHOME'}/collect/modelcol", "$ENV{'GSDLHOME'}/collect/$collection");
190print STDERR "\n\nThe new collection is in $ENV{'GSDLHOME'}/collect/$collection.\n\n";
191
Note: See TracBrowser for help on using the repository browser.