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

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

altered mkcol.pl so that it doesn't copy CVS directories from modelcol

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