source: trunk/gsdl/bin/script/exportcol.pl@ 6926

Last change on this file since 6926 was 6926, checked in by mdewsnip, 20 years ago

Changed the way display in different languages is done. Instead of passing a language variable throughout the process, the desired resource bundle is explicitly loaded during the initialization of each program (buildcol.pl, classinfo.pl, exportcol.pl, import.pl mkcol.pl, pluginfo.pl).
VS: ----------------------------------------------------------------------

  • Property svn:keywords set to Author Date Id Revision
File size: 10.9 KB
Line 
1#!/usr/bin/perl -w
2
3###########################################################################
4#
5# exportcol.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
28BEGIN {
29 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
30 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
31}
32
33use util;
34use parsargv;
35use printusage;
36
37my $arguments =
38 [ { 'name' => "language",
39 'desc' => "{scripts.language}",
40 'type' => "string",
41 'reqd' => "no" },
42 { 'name' => "out",
43 'desc' => "{exportcol.out}",
44 'type' => "string",
45 'deft' => "STDERR",
46 'reqd' => "no" },
47 { 'name' => "cdname",
48 'desc' => "{exportcol.cdname}",
49 'type' => "string",
50 'deft' => "Greenstone Collections",
51 'reqd' => "no" }, ];
52
53my $options = { 'name' => "exportcol.pl",
54 'desc' => "{exportcol.desc}",
55 'args' => $arguments };
56
57sub gsprintf
58{
59 return &gsprintf::gsprintf(@_);
60}
61
62
63#sub print_usage {
64# print STDERR "\n";
65# print STDERR "exportcol.pl: Exports collection for writing to CD-ROM.\n\n";
66# print STDERR " usage: $0 [options] collection-name\n\n";
67# print STDERR " -out Filename or handle to print debug info to.\n";
68# print STDERR " The default is STDERR\n";
69# print STDERR " -cdname The name of the cd - this is what will appear in the start menu once the cd is installed.\n";
70# print STDERR " The default is 'Greenstone Collections'.\n\n";
71#}
72
73&main();
74
75sub main {
76 my ($out, $cdname);
77
78 my $xml = 0;
79
80 if (!parsargv::parse(\@ARGV,
81 'language/.*/', \$language,
82 'out/.*/STDERR', \$out,
83 'cdname/.*/', \$cdname,
84 q^xml^, \$xml)) {
85
86 &PrintUsage::print_txt_usage($options, "{exportcol.params}");
87 die "\n";
88 }
89
90 # Load the appropriate resource bundle for the language specified
91 # If $language is not defined, the default resource bundle will be loaded
92 &gsprintf::load_resource_bundle($language);
93
94 if ($xml) {
95 &PrintUsage::print_xml_usage($options);
96 die "\n";
97 }
98
99 my $dirname="";
100 if ($cdname eq "") {
101 $cdname = "Greenstone Collections";
102 $dirname = "exported_collections";
103 } else {
104 $dirname = $cdname;
105 $dirname =~ s/\s//g;
106 $dirname = "exported_".$dirname;
107 }
108
109 my @coll_list = @ARGV;
110
111 if (not @coll_list) { # empty list
112 &PrintUsage::print_txt_usage($options, "{exportcol.params}");
113 exit(1);
114 }
115
116 my $close_out = 0;
117 if ($out !~ /^(STDERR|STDOUT)$/i) {
118 open (OUT, ">$out") ||
119 (&gsprintf(STDERR, "{common.cannot_open_output_file}\n", $out) && die);
120 $out = OUT;
121 $close_out = 1;
122 }
123
124 # check each collection
125 my @valid_coll_list = ();
126 foreach $c (@coll_list) {
127 my $colldir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $c);
128 if (! -d $colldir) {
129 &gsprintf($out, "{exportcol.coll_not_found}\n", $c, $colldir);
130 next;
131 }
132 my $colindexdir = &util::filename_cat ($colldir, "index");
133 my $coletcdir = &util::filename_cat ($colldir, "etc");
134 if ((!-d $colindexdir) || (!-d $coletcdir)) {
135 &gsprintf($out, "{exportcol.coll_dirs_not_found}\n", $c);
136 &gsprintf($out, " $colindexdir\n");
137 &gsprintf($out, " $coletcdir\n");
138 next;
139 }
140 # the collection seems ok, we add it to the valid coll list
141 push @valid_coll_list, $c;
142 }
143
144 if (not @valid_coll_list) {
145 # no valid colls left
146 &gsprintf($out, "{exportcol.fail} {exportcol.no_valid_colls}\n");
147 die "\n";
148 }
149
150 # create exported directory
151 my $topdir = &util::filename_cat ($ENV{'GSDLHOME'}, "tmp", $dirname);
152 &util::mk_all_dir ($topdir);
153 if (!-d $topdir) {
154 &gsprintf($out, "{exportcol.fail} {exportcol.couldnt_create_dir}\n", $topdir);
155 die "\n";
156 }
157
158 # make other directories (we'll assume that if we created topdir
159 # successfully there'll be no problems creating these)
160 my $gsdldir = &util::filename_cat ($topdir, "gsdl");
161 &util::mk_all_dir ($gsdldir);
162 my $collectdir = &util::filename_cat ($gsdldir, "collect");
163 &util::mk_all_dir ($collectdir);
164 my $etcdir = &util::filename_cat ($gsdldir, "etc");
165 &util::mk_all_dir ($etcdir);
166 my $binjavadir = &util::filename_cat ($gsdldir, "bin", "java");
167 &util::mk_all_dir ($binjavadir);
168
169 # create the install.cfg file
170 my $installcfg = &util::filename_cat ($topdir, "install.cfg");
171 if (!open (INSTALLCFG, ">$installcfg")) {
172 &gsprintf($out, "{exportcol.fail} {exportcol.couldnt_create_file}\n", $installcfg);
173 die "\n";
174 }
175 print INSTALLCFG "CompanyName:New Zealand Digital Library\n";
176 print INSTALLCFG "CollectionName:$cdname\n";
177 print INSTALLCFG "CollectionDirName:$cdname\n";
178 print INSTALLCFG "CollectionVersion:1.0\n";
179 print INSTALLCFG "CollectionVolume:1\n";
180 print INSTALLCFG "ProgramGroupName:Greenstone\n";
181 close INSTALLCFG;
182
183 # create the manifest.cfg file
184 my $manifestcfg = &util::filename_cat ($topdir, "manifest.cfg");
185 if (!open (MANIFESTCFG, ">$manifestcfg")) {
186 &gsprintf($out, "{exportcol.fail} {exportcol.couldnt_create_file}\n", $manifestcfg);
187 die "\n";
188 }
189 print MANIFESTCFG "all:\n";
190 print MANIFESTCFG " {library} {collection}\n\n";
191 print MANIFESTCFG "library:\n";
192 print MANIFESTCFG " net32 net16 server.exe\n\n";
193 print MANIFESTCFG "database:\n";
194 print MANIFESTCFG ' etc ';
195 foreach $c (@valid_coll_list) {
196 print MANIFESTCFG "collect\\$c\\index\\text\\$c.ldb ";
197 }
198 print MANIFESTCFG "\n\n";
199 print MANIFESTCFG "collection:\n";
200 print MANIFESTCFG " collect etc images macros mappings bin\n";
201 close MANIFESTCFG;
202
203 #create the autorun.inf file
204 my $autoruninf = &util::filename_cat ($topdir, "Autorun.inf");
205 if (!open (AUTORUNINF, ">$autoruninf")) {
206 &gsprintf($out, "{exportcol.fail} {exportcol.couldnt_create_file}\n", $autoruninf);
207 die "\n";
208 }
209
210 print AUTORUNINF "[autorun]\n";
211 print AUTORUNINF "OPEN=Setup.exe\n";
212 close AUTORUNINF;
213
214 # copy the necessary stuff from GSDLHOME
215 my $imagesdir = &util::filename_cat ($ENV{'GSDLHOME'}, "images");
216 my $macrosdir = &util::filename_cat ($ENV{'GSDLHOME'}, "macros");
217 my $mappingsdir = &util::filename_cat ($ENV{'GSDLHOME'}, "mappings");
218 my $maincfg = &util::filename_cat ($ENV{'GSDLHOME'}, "etc", "main.cfg");
219 my $serverexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "server.exe");
220 my $gssetupexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "gssetup.exe");
221 my $setupexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "Setup.exe");
222 my $net32dir = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "net32");
223 my $net16dir = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "net16");
224 my $netscapedir = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "netscape");
225 my $win32sdir = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "Win32s");
226 my $phindjar = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "java", "Phind.jar");
227 my $gsdlcollageappletjar = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "java", "GsdlCollageApplet.jar");
228
229 if ((!-d $imagesdir) || (!-d $macrosdir) || (!-d $mappingsdir) || (!-e $maincfg) ||
230 (!-e $serverexe) || (!-e $gssetupexe) || (!-e $setupexe) || (!-d $net32dir) ||
231 (!-d $net16dir) || (!-d $netscapedir) || (!-d $win32sdir) || (!-e $phindjar) ||
232 (!-e $gsdlcollageappletjar)) {
233 &gsprintf($out, "{exportcol.fail} {exportcol.non_exist_files}\n");
234 &gsprintf($out, " $imagesdir\n");
235 &gsprintf($out, " $macrosdir\n");
236 &gsprintf($out, " $mappingsdir\n");
237 &gsprintf($out, " $maincfg\n");
238 &gsprintf($out, " $serverexe\n");
239 &gsprintf($out, " $gssetupexe\n");
240 &gsprintf($out, " $setupexe\n");
241 &gsprintf($out, " $net32dir\n");
242 &gsprintf($out, " $net16dir\n");
243 &gsprintf($out, " $netscapedir\n");
244 &gsprintf($out, " $win32sdir\n");
245 &gsprintf($out, " $phindjar\n");
246 &gsprintf($out, " $gsdlcollageappletjar\n");
247 die "\n";
248 }
249
250 &util::cp_r ($imagesdir, $gsdldir);
251 &util::cp_r ($macrosdir, $gsdldir);
252 &util::cp_r ($mappingsdir, $gsdldir);
253 &util::cp ($maincfg, $etcdir);
254 &util::cp ($serverexe, $gsdldir);
255 &util::cp ($gssetupexe, $topdir);
256 &util::cp ($setupexe, $topdir);
257 &util::cp_r ($net32dir, $gsdldir);
258 &util::cp_r ($net16dir, $gsdldir);
259 &util::cp_r ($netscapedir, $topdir);
260 &util::cp_r ($win32sdir, $topdir);
261 &util::cp ($phindjar, $binjavadir);
262 &util::cp ($gsdlcollageappletjar, $binjavadir);
263
264 # now change the home.dm macro file to a simple version
265 my $newmacrodir = &util::filename_cat ($gsdldir, "macros");
266 my $exporthome = &util::filename_cat ($newmacrodir, "exported_home.dm");
267 my $oldhome = &util::filename_cat ($newmacrodir, "home.dm");
268 if (-e $exporthome) {
269 &util::rm($oldhome);
270 &util::mv($exporthome, $oldhome);
271 }
272
273 # copy the collections over
274 foreach $c (@valid_coll_list) {
275 #old directories
276 my $colldir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $c);
277 my $colindexdir = &util::filename_cat ($colldir, "index");
278 my $coletcdir = &util::filename_cat ($colldir, "etc");
279 my $colimagesdir = &util::filename_cat ($colldir, "images");
280 # new coll directory
281 my $newcoldir = &util::filename_cat ($collectdir, $c);
282
283 &util::mk_all_dir ($newcoldir);
284 &util::cp_r ($colindexdir, $newcoldir);
285 &util::cp_r ($coletcdir, $newcoldir);
286 &util::cp_r ($colimagesdir, $newcoldir) if (-e $colimagesdir);
287
288 # now we need to check the collect.cfg file to make sure it's public
289 my $collectcfg = &util::filename_cat ($newcoldir, "etc", "collect.cfg");
290 open INFILE, "<$collectcfg";
291 open OUTFILE, ">$collectcfg.tmp";
292 while ($line = <INFILE>) {
293 if ($line =~ /^\s*public\s+false/) {
294 print OUTFILE "public\ttrue\n";
295 last; # stop matching once we have found the line
296 } else {
297 print OUTFILE "$line";
298 }
299 }
300 # continue with no checking
301 while ($line = <INFILE>) {
302 print OUTFILE "$line";
303 }
304 close INFILE;
305 close OUTFILE;
306 &util::mv("$collectcfg.tmp", $collectcfg);
307 }
308 &gsprintf($out, "{exportcol.success}");
309
310 my $successcolls = "";
311 my $first = 1;
312 foreach $c (@valid_coll_list) {
313 if ($first) {
314 $first=0;
315 } else {
316 $successcolls .=", ";
317 }
318 $successcolls .= "$c";
319 }
320
321 &gsprintf($out, "{exportcol.output_dir}\n", $successcolls, $topdir);
322 &gsprintf($out, "{exportcol.instructions}\n");
323 close OUT if $close_out;
324}
325
Note: See TracBrowser for help on using the repository browser.