1 | #!perl -w
|
---|
2 |
|
---|
3 | ###########################################################################
|
---|
4 | #
|
---|
5 | # webpage_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 | # This program is a webpage wrapper to the mkcol.pl process
|
---|
29 |
|
---|
30 | package webpage_mkcol;
|
---|
31 |
|
---|
32 | use CGI;
|
---|
33 | use GSDLHOME;
|
---|
34 | use gflock;
|
---|
35 |
|
---|
36 | require util;
|
---|
37 | require webpageutil;
|
---|
38 |
|
---|
39 | sub parse_cgiargs
|
---|
40 | {
|
---|
41 | # get arguments
|
---|
42 | my $cgi = new CGI;
|
---|
43 | my %args = ();
|
---|
44 |
|
---|
45 | foreach $p ($cgi->param())
|
---|
46 | {
|
---|
47 | $args{$p} = $cgi->param($p);
|
---|
48 | }
|
---|
49 |
|
---|
50 | return \%args;
|
---|
51 | }
|
---|
52 |
|
---|
53 |
|
---|
54 | sub get_unique_dirname
|
---|
55 | {
|
---|
56 | my ($args) = @_;
|
---|
57 |
|
---|
58 | my $dirname = "";
|
---|
59 |
|
---|
60 | my $fullname = $args->{'bc1fullname'};
|
---|
61 | my $in_gsdl_area = $args->{'bc1ingsdlarea'};
|
---|
62 | my $copy_dir = $args->{'bc1copydir'};
|
---|
63 |
|
---|
64 | # if inputdir is in gsdl area then need to extract existing dirname
|
---|
65 | if (($in_gsdl_area eq "yes") && (($copy_dir eq "no")))
|
---|
66 | {
|
---|
67 | my $inputdir = $args->{'bc1inputdir'};
|
---|
68 | my $dirsep_re = &util::get_re_dirsep();
|
---|
69 | my @id_split = split(/$dirsep_re/,$inputdir);
|
---|
70 | while (@id_split>0)
|
---|
71 | {
|
---|
72 | $dirname = pop(@id_split);
|
---|
73 | last if ($dirname =~ m/(import|building)/i);
|
---|
74 | }
|
---|
75 | $dirname = pop(@id_split);
|
---|
76 |
|
---|
77 | # check to see if config file already exists
|
---|
78 | my $cfg_filename
|
---|
79 | = &util::filename_cat($ENV{'GSDLHOME'},"collect",$dirname,
|
---|
80 | "etc","collect.cfg");
|
---|
81 | if (-e $cfg_filename)
|
---|
82 | {
|
---|
83 | &webpageutil::error_location($args,"_messconfigexists_");
|
---|
84 | return "";
|
---|
85 | }
|
---|
86 | }
|
---|
87 | else
|
---|
88 | {
|
---|
89 | # clean up input for heuristic that derives directory name for a
|
---|
90 | # new collection
|
---|
91 | $fullname =~ s/\s+/ /g;
|
---|
92 | $fullname =~ tr/[A-Z]/[a-z]/;
|
---|
93 | my @fn_split = split(" ",$fullname);
|
---|
94 | map { $_ =~ s/\W//g } @fn_split; # remove any non-word characters
|
---|
95 |
|
---|
96 | my $no_words = scalar(@fn_split);
|
---|
97 | if ($no_words == 0)
|
---|
98 | {
|
---|
99 | &webpageutil::error_location($args,"_messnofn_");
|
---|
100 | return "";
|
---|
101 | }
|
---|
102 |
|
---|
103 | my $use_words = ($no_words<=6) ? $no_words : 6;
|
---|
104 | my $substr_len = int(6/$use_words);
|
---|
105 |
|
---|
106 | my $i;
|
---|
107 | for ($i=0; $i<$use_words; $i++)
|
---|
108 | {
|
---|
109 | $dirname .= substr($fn_split[$i],0,$substr_len);
|
---|
110 | }
|
---|
111 |
|
---|
112 | # check to see if dirname is unique
|
---|
113 | my $fulldirname
|
---|
114 | = &util::filename_cat($ENV{'GSDLHOME'},"collect",$dirname);
|
---|
115 | if (-e $fulldirname)
|
---|
116 | {
|
---|
117 | my $version = 0;
|
---|
118 | do
|
---|
119 | {
|
---|
120 | $version++;
|
---|
121 | $fulldirname
|
---|
122 | = &util::filename_cat($ENV{'GSDLHOME'},"collect",
|
---|
123 | "${dirname}v$version");
|
---|
124 |
|
---|
125 | } while (-e $fulldirname);
|
---|
126 |
|
---|
127 | $dirname = "${dirname}v$version";
|
---|
128 | }
|
---|
129 | }
|
---|
130 |
|
---|
131 | return $dirname;
|
---|
132 | }
|
---|
133 |
|
---|
134 |
|
---|
135 | sub main
|
---|
136 | {
|
---|
137 | # get arguments
|
---|
138 | my $args = parse_cgiargs();
|
---|
139 |
|
---|
140 | # get unique dirname
|
---|
141 | my $unique_dirname = get_unique_dirname($args);
|
---|
142 | if ($unique_dirname ne "")
|
---|
143 | {
|
---|
144 | my $fullname = $args->{'bc1fullname'};
|
---|
145 | my $contact_email = $args->{'bc1contactemail'};
|
---|
146 | my $about_desc = $args->{'bc1aboutdesc'};
|
---|
147 | my $src_format = $args->{'bc1srcformat'};
|
---|
148 | my $input_dir = $args->{'bc1inputdir'};
|
---|
149 | my $copy_dir = $args->{'bc1copydir'};
|
---|
150 | my $in_gsdl_area = $args->{'bc1ingsdlarea'};
|
---|
151 | my $acronyms = $args->{'bc1acronyms'};
|
---|
152 |
|
---|
153 | my $cmd = "perl ";
|
---|
154 | $cmd .= &util::filename_cat($ENV{'GSDLHOME'}, "bin", "script", "mkcol.pl");
|
---|
155 | $cmd .= " -title \"$fullname\"";
|
---|
156 | $cmd .= " -creator $contact_email";
|
---|
157 | $cmd .= " -about \"$about_desc\"";
|
---|
158 | $cmd .= " -plugin \"GMLPlug\"";
|
---|
159 | if ($src_format eq "HTML") {
|
---|
160 | $cmd .= " -plugin \"HTMLPlug -keep_head\"";
|
---|
161 | } else {
|
---|
162 | $cmd .= " -plugin \"${src_format}Plug\"";
|
---|
163 | }
|
---|
164 | $cmd .= " -plugin \"ArcPlug\"";
|
---|
165 | $cmd .= " -plugin \"RecPlug\"";
|
---|
166 | $cmd .= " $unique_dirname";
|
---|
167 |
|
---|
168 | my $status = system($cmd);
|
---|
169 | $status /= 256;
|
---|
170 |
|
---|
171 | if ($status == 0)
|
---|
172 | {
|
---|
173 | # append copydir and input_dir to end of collect.cfg we'll also
|
---|
174 | # append DocumentUseHTML if processing HTML docs
|
---|
175 | my $cfg_filename
|
---|
176 | = &util::filename_cat($ENV{'GSDLHOME'},"collect",$unique_dirname,
|
---|
177 | "etc","collect.cfg");
|
---|
178 | if (open(CFGAPP,">>$cfg_filename"))
|
---|
179 | {
|
---|
180 | if (&gflock::lock (webpage_mkcol::CFGAPP)) {
|
---|
181 | print CFGAPP "\n";
|
---|
182 |
|
---|
183 | if ($src_format eq "HTML") {
|
---|
184 | print CFGAPP "format\tDocumentUseHTML\ttrue\n\n";
|
---|
185 | }
|
---|
186 |
|
---|
187 | print CFGAPP "building\tinputdir\t\"$input_dir\"\n";
|
---|
188 | print CFGAPP "building\tcopydir\t\t$copy_dir\n";
|
---|
189 | print CFGAPP "building\tingsdlarea\t$in_gsdl_area\n";
|
---|
190 | &gflock::unlock (webpage_mkcol::CFGAPP);
|
---|
191 | close(CFGAPP);
|
---|
192 | }
|
---|
193 | else
|
---|
194 | {
|
---|
195 | # problem locking file
|
---|
196 | my $mess = "Unable to lock collection";
|
---|
197 | $mess .= " configuration file: $cfg_filename";
|
---|
198 | &webpageutil::error_location($args,$mess);
|
---|
199 | close(CFGAPP);
|
---|
200 | return;
|
---|
201 | }
|
---|
202 | }
|
---|
203 | else
|
---|
204 | {
|
---|
205 | # problem
|
---|
206 | my $mess = "Unable to append to collection";
|
---|
207 | $mess .= " configuration file: $cfg_filename";
|
---|
208 | &webpageutil::error_location($args,$mess);
|
---|
209 | return;
|
---|
210 | }
|
---|
211 | }
|
---|
212 | else
|
---|
213 | {
|
---|
214 | my $mess = "An error was encountered: error status = $status";
|
---|
215 | &webpageutil::error_location($args,$mess);
|
---|
216 | return;
|
---|
217 | }
|
---|
218 | }
|
---|
219 | else
|
---|
220 | {
|
---|
221 | my $mess = "No unique directory name specified for collection";
|
---|
222 | &webpageutil::error_location($args,$mess);
|
---|
223 | return;
|
---|
224 | }
|
---|
225 |
|
---|
226 | my $mess_url = "$args->{'httpbuild'}&bca=mess&bc1dirname=$unique_dirname";
|
---|
227 | print "Location: $mess_url&head=_headdone_&mess=_messdonenewcol_\n\n";
|
---|
228 |
|
---|
229 | }
|
---|
230 |
|
---|
231 | &main();
|
---|