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

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

Initial revision

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 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'}/lib");
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(!/^\.\.?$/, 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 (!defined($creator) || $creator eq "") {
116 print STDERR "The creator was not defined. This variable is\n";
117 print STDERR "needed to recognise duplicate collection names.\n";
118 die "\n";
119}
120
121if (!defined($maintainer) || $maintainer eq "") {
122 $maintainer = $creator;
123}
124
125$public = "true" unless defined $public;
126$beta = "true" unless defined $beta;
127
128srand(time);
129$key = int(rand()*100000000.0) + int(rand()*100000000.0);
130
131# get capitalised version of the collection
132$capcollection = $collection;
133$capcollection =~ tr/a-z/A-Z/;
134
135
136# get the strings to include.
137$indexesstr = join ("\t", @indexes);
138$indexestextstr = "";
139for ($i=0; $i<scalar(@indexestext); $i++) {
140 $indexestextstr .= "_$indexes[$i]_[] {$indexestext[$i]}\n";
141}
142
143
144# make sure the model collection exists
145die "Cannot find the model collection $ENV{'GSDLHOME'}/collect/modelcol" unless
146 (-d "$ENV{'GSDLHOME'}/collect/modelcol");
147
148# make sure this collection does not already exist
149if (-e "$ENV{'GSDLHOME'}/collect/$collection") {
150 print STDERR "This collection already exists\n";
151 die "\n";
152}
153
154
155# start creating the collection
156print STDERR "Creating the collection $collection\n\n";
157&traverse_dir ("$ENV{'GSDLHOME'}/collect/modelcol", "$ENV{'GSDLHOME'}/collect/$collection");
158print STDERR "\n\nThe new collection is in $ENV{'GSDLHOME'}/collect/$collection.\n\n";
159
Note: See TracBrowser for help on using the repository browser.