source: main/tags/2.60/gsdl/bin/script/mkcol.pl@ 25196

Last change on this file since 25196 was 9060, checked in by kjdon, 19 years ago

added ImagePLug to plugin list, also -smart_block option to htmlplug, and -use_metadata_files to RecPLug

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 8.2 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 die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
38 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
39}
40
41use parsargv;
42use util;
43use cfgread;
44use gsprintf;
45use printusage;
46
47my $arguments =
48 [ { 'name' => "creator",
49 'desc' => "{mkcol.creator}",
50 'type' => "string",
51 'reqd' => "no" },
52 { 'name' => "optionfile",
53 'desc' => "{mkcol.optionfile}",
54 'type' => "string",
55 'reqd' => "no" },
56 { 'name' => "maintainer",
57 'desc' => "{mkcol.maintainer}",
58 'type' => "string",
59 'reqd' => "no" },
60 { 'name' => "collectdir",
61 'desc' => "{mkcol.collectdir}",
62 'type' => "string",
63 'deft' => &util::filename_cat ($ENV{'GSDLHOME'}, "collect"),
64 'reqd' => "no" },
65 { 'name' => "public",
66 'desc' => "{mkcol.public}",
67 'type' => "string",
68 'deft' => "true",
69 'reqd' => "no" },
70 { 'name' => "title",
71 'desc' => "{mkcol.title}",
72 'type' => "string",
73 'reqd' => "no" },
74 { 'name' => "about",
75 'desc' => "{mkcol.about}",
76 'type' => "string",
77 'reqd' => "no" },
78 { 'name' => "plugin",
79 'desc' => "{mkcol.plugin}",
80 'type' => "string",
81 'reqd' => "no" },
82 { 'name' => "quiet",
83 'desc' => "{mkcol.quiet}",
84 'type' => "flag",
85 'reqd' => "no" },
86 { 'name' => "language",
87 'desc' => "{scripts.language}",
88 'type' => "string",
89 'reqd' => "no" },
90 { 'name' => "win31compat",
91 'desc' => "{mkcol.win31compat}",
92 'type' => "string",
93 'deft' => "true",
94 'reqd' => "no" } ];
95
96my $options = { 'name' => "mkcol.pl",
97 'desc' => "{mkcol.desc}",
98 'args' => $arguments };
99
100sub gsprintf
101{
102 return &gsprintf::gsprintf(@_);
103}
104
105
106sub traverse_dir
107{
108 my ($modeldir, $coldir) = @_;
109 my ($newfile, @filetext);
110
111 if (!(-e $coldir)) {
112
113 my $store_umask = umask(0002);
114 my $mkdir_ok = mkdir ($coldir, 0777);
115 umask($store_umask);
116
117 if (!$mkdir_ok)
118 {
119 die "$!";
120 }
121 }
122
123 opendir(DIR, $modeldir) ||
124 (&gsprintf(STDERR, "{common.cannot_read}\n", $modeldir) && die);
125 my @files = grep(!/^(\.\.?|CVS)$/, readdir(DIR));
126 closedir(DIR);
127
128 foreach $file (@files)
129 {
130 my $thisfile = &util::filename_cat ($modeldir, $file);
131 if (-d $thisfile) {
132 my $colfiledir = &util::filename_cat ($coldir, $file);
133 traverse_dir ($thisfile, $colfiledir);
134
135 } else {
136 my $destfile = $file;
137 $destfile =~ s/^modelcol/$collection/;
138 $destfile =~ s/^MODELCOL/$capcollection/;
139 &gsprintf(STDOUT, "{mkcol.doing_replacements}\n", $destfile)
140 unless $quiet;
141 $destfile = &util::filename_cat ($coldir, $destfile);
142
143 open (INFILE, $thisfile) ||
144 (&gsprintf(STDERR, "{common.cannot_read_file}\n", $thisfile) && die);
145 open (OUTFILE, ">$destfile") ||
146 (&gsprintf(STDERR, "{common.cannot_create_file}\n", $destfile) && die);
147
148 while (defined ($line = <INFILE>)) {
149 $line =~ s/\*\*collection\*\*/$collection/g;
150 $line =~ s/\*\*COLLECTION\*\*/$capcollection/g;
151 $line =~ s/\*\*creator\*\*/$creator/g;
152 $line =~ s/\*\*maintainer\*\*/$maintainer/g;
153 $line =~ s/\*\*public\*\*/$public/g;
154 $line =~ s/\*\*title\*\*/$title/g;
155 $line =~ s/\*\*about\*\*/$about/g;
156 $line =~ s/\*\*plugins\*\*/$pluginstring/g;
157
158 print OUTFILE $line;
159 }
160
161 close (OUTFILE);
162 close (INFILE);
163 }
164 }
165}
166
167# get and check options
168sub parse_args {
169 my ($argref) = @_;
170 if (!&parsargv::parse($argref,
171 'language/.*/', \$language,
172 'optionfile/.*/', \$optionfile,
173 'collectdir/.*/', \$collectdir,
174 'creator/\w+\@[\w\.]+/', \$creator,
175 'maintainer/\w+\@[\w\.]+/', \$maintainer,
176 'public/true|false/true', \$public,
177 'title/.+/', \$title,
178 'about/.+/', \$about,
179 'plugin/.+', \@plugin,
180 'quiet', \$quiet,
181 'win31compat/true|false/true', \$win31compat,
182 'gli', \$gli,
183 q^xml^, \$xml
184 )) {
185 &PrintUsage::print_txt_usage($options, "{mkcol.params}");
186 die "\n";
187 }
188}
189
190sub main {
191
192 &parse_args (\@ARGV);
193
194 # If $language has been specified, load the appropriate resource bundle
195 # (Otherwise, the default resource bundle will be loaded automatically)
196 if ($language) {
197 &gsprintf::load_language_specific_resource_bundle($language);
198 }
199
200 if ($xml) {
201 &PrintUsage::print_xml_usage($options);
202 die "\n";
203 }
204
205 if ($gli) { # the gli wants strings to be in UTF-8
206 &gsprintf::output_strings_in_UTF8;
207 }
208
209 if ($optionfile =~ /\w/) {
210 open (OPTIONS, $optionfile) ||
211 (&gsprintf(STDERR, "{common.cannot_open}\n", $optionfile) && die);
212 my $line = [];
213 my $options = [];
214 while (defined ($line = &cfgread::read_cfg_line ('mkcol::OPTIONS'))) {
215 push (@$options, @$line);
216 }
217 close OPTIONS;
218 &parse_args ($options);
219 }
220
221 # load default plugins if none were on command line
222 if (!scalar(@plugin)) {
223 @plugin = (ZIPPlug,GAPlug,TEXTPlug,"HTMLPlug -smart_block","EMAILPlug",
224 PDFPlug,RTFPlug,WordPlug,PSPlug,ImagePlug,NULPlug,ArcPlug,"RecPlug -use_metadata_files");
225 }
226
227 # get and check the collection name
228 ($collection) = @ARGV;
229 if (!defined($collection)) {
230 &gsprintf(STDOUT, "{mkcol.no_colname}\n");
231 &PrintUsage::print_txt_usage($options, "{mkcol.params}");
232 die "\n";
233 }
234
235 if (($win31compat eq "true") && (length($collection)) > 8) {
236 &gsprintf(STDOUT, "{mkcol.long_colname}\n");
237 die "\n";
238 }
239
240 if ($collection eq "modelcol") {
241 &gsprintf(STDOUT, "{mkcol.bad_name_modelcol}\n");
242 die "\n";
243 }
244
245 if ($collection eq "CVS") {
246 &gsprintf(STDOUT, "{mkcol.bad_name_cvs}\n");
247 die "\n";
248 }
249
250 # We don't want creator to be required anymore - John Thompson 28-11-2003
251 #if (!defined($creator) || $creator eq "") {
252 # &gsprintf(STDOUT, "{mkcol.creator_undefined}\n");
253 # die "\n";
254 #}
255
256 #Of course thats means we don't want to default maintainer unless a creator is provided
257 if (defined($creator) && (!defined($maintainer) || $maintainer eq "")) {
258 $maintainer = $creator;
259 }
260
261 $public = "true" unless defined $public;
262
263 if (!defined($title) || $title eq "") {
264 $title = $collection;
265 }
266
267 # get capitalised version of the collection
268 $capcollection = $collection;
269 $capcollection =~ tr/a-z/A-Z/;
270
271 # get the strings to include.
272 $pluginstring = "";
273 foreach $plugin (@plugin) {
274 $pluginstring .= "plugin $plugin\n";
275 }
276
277 $mdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", "modelcol");
278 if (defined $collectdir && $collectdir =~ /\w/) {
279 if (!-d $collectdir) {
280 &gsprintf(STDOUT, "{mkcol.no_collectdir}\n", $collectdir);
281 die "\n";
282 }
283 $cdir = &util::filename_cat ($collectdir, $collection);
284 } else {
285 $cdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collection);
286 }
287
288 # make sure the model collection exists
289 (&gsprintf(STDERR, "{mkcol.cannot_find_modelcol}\n", $mdir) && die) unless (-d $mdir);
290
291 # make sure this collection does not already exist
292 if (-e $cdir) {
293 &gsprintf(STDOUT, "{mkcol.col_already_exists}\n");
294 die "\n";
295 }
296
297 # start creating the collection
298 &gsprintf(STDOUT, "\n{mkcol.creating_col}...\n", $collection)
299 unless $quiet;
300 &traverse_dir ($mdir, $cdir);
301 &gsprintf(STDOUT, "\n{mkcol.success}\n", $cdir)
302 unless $quiet;
303}
304
305&main ();
Note: See TracBrowser for help on using the repository browser.