Changeset 28460
- Timestamp:
- 2013-10-16T17:37:29+13:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/util.pm
r28394 r28460 316 316 317 317 318 sub get_collectlevel_tmp_dir 319 { 320 my $tmp_dirname = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, "tmp"); 321 &FileUtils::makeDirectory($tmp_dirname) if (!-e $tmp_dirname); 322 323 return $tmp_dirname; 324 } 325 326 318 327 sub filename_to_regex { 319 328 my $filename = shift (@_); … … 373 382 if ($join_char eq ";") { 374 383 $pathname =~ s/[\\\/]+/\\/g; 384 if ($^O eq "cygwin") { 385 # Once we've collapsed muliple (potentialy > 2) slashes 386 # For cygwin, actually want things double-backslahed 387 $pathname =~ s/\\/\\\\/g; 388 } 389 375 390 } else { 376 391 $pathname =~ s/[\/]+/\//g; … … 412 427 413 428 429 sub makeFilenameJavaCygwinCompatible 430 { 431 my ($java_filename) = @_; 432 433 if ($^O eq "cygwin") { 434 # To be used with a Java program, but under Cygwin 435 # Because the java binary that is native to Windows, need to 436 # convert the Cygwin paths (i.e. Unix style) to be Windows 437 # compatible 438 439 $java_filename = `cygpath -wp "$java_filename"`; 440 chomp($java_filename); 441 $java_filename =~ s%\\%\\\\%g; 442 } 443 444 return $java_filename; 445 } 414 446 415 447 sub tidy_up_oid { … … 1125 1157 1126 1158 1159 1160 # 1161 # The following comaes from activate.pl 1162 # 1163 # Designed to work with a server included with GS. 1164 # - For GS3, we ask ant for the library URL. 1165 # - For GS2, we derive the URL from the llssite.cfg file. 1166 1167 sub get_full_greenstone_url_prefix 1168 { 1169 # if already set on a previous occasion, just return that 1170 # (Don't want to keep repeating this: cost of re-opening and scanning files.) 1171 return $ENV{'GREENSTONE_URL_PREFIX'} if($ENV{'GREENSTONE_URL_PREFIX'}); 1172 1173 my $gs_mode = ($ENV{'GSDL3SRCHOME'}) ? "gs3" : "gs2"; 1174 1175 my $url = undef; 1176 1177 if($gs_mode eq "gs2") { 1178 my $llssite_cfg = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'}, "llssite.cfg"); 1179 1180 if(-f $llssite_cfg) { 1181 # check llssite.cfg for line with url property 1182 # for server.exe also need to use portnumber and enterlib properties 1183 1184 # Read in the entire contents of the file in one hit 1185 if (!open (FIN, $llssite_cfg)) { 1186 print STDERR "util::get_library_URL() failed to open $llssite_cfg ($!)\n"; 1187 return undef; 1188 } 1189 1190 my $contents; 1191 sysread(FIN, $contents, -s FIN); 1192 close(FIN); 1193 1194 my @lines = split(/[\n\r]+/, $contents); # split on carriage-returns and/or linefeeds 1195 my $enterlib = ""; 1196 my $portnumber = ""; # will remain empty (implicit port 80) unless it's specifically been assigned 1197 1198 foreach my $line (@lines) { 1199 if($line =~ m/^url=(.*)$/) { 1200 $url = $1; 1201 } elsif($line =~ m/^enterlib=(.*)$/) { 1202 $enterlib = $1; 1203 } elsif($line =~ m/^portnumber=(.*)$/) { 1204 $portnumber = $1; 1205 } 1206 } 1207 1208 if(!$url) { 1209 return undef; 1210 } 1211 elsif($url eq "URL_pending") { # library is not running 1212 # do not process url=URL_pending in the file, since for server.exe 1213 # this just means the Enter Library button hasn't been pressed yet 1214 $url = undef; 1215 } 1216 else { 1217 # In the case of server.exe, need to do extra work to get the proper URL 1218 # But first, need to know whether we're indeed dealing with server.exe: 1219 1220 # compare the URL's domain to the full URL 1221 # E.g. for http://localhost:8383/greenstone3/cgi-bin, the domain is localhost:8383 1222 my $uri = URI->new( $url ); 1223 my $host = $uri->host; 1224 #print STDERR "@@@@@ host: $host\n"; 1225 if($url =~ m/http:\/\/$host(\/)?$/) { 1226 #if($url !~ m/http:\/\/$host:$portnumber(\/)?/ || $url =~ m/http:\/\/$host(\/)?$/) { 1227 # (if the URL does not contain the portnumber, OR if the port is implicitly 80 and) 1228 # If the domain with http:// prefix is completely the same as the URL, assume server.exe 1229 # then the actual URL is the result of suffixing the port and enterlib properties in llssite.cfg 1230 $url = $url.":".$portnumber.$enterlib; 1231 } # else, apache web server 1232 1233 } 1234 } 1235 } elsif($gs_mode eq "gs3") { 1236 # Either check build.properties for tomcat.server, tomcat.port and app.name (and default servlet name). 1237 # app.name is stored in app.path by build.xml. Need to move app.name in build.properties from build.xml 1238 1239 # Or, run the new target get-default-servlet-url 1240 # the output can look like: 1241 # 1242 # Buildfile: build.xml 1243 # [echo] os.name: Windows Vista 1244 # 1245 # get-default-servlet-url: 1246 # [echo] http://localhost:8383/greenstone3/library 1247 # BUILD SUCCESSFUL 1248 # Total time: 0 seconds 1249 1250 #my $output = qx/ant get-default-servlet-url/; # backtick operator, to get STDOUT (else 2>&1) 1251 # - see http://stackoverflow.com/questions/799968/whats-the-difference-between-perls-backticks-system-and-exec 1252 1253 # The get-default-servlet-url ant target can be run from anywhere by specifying the 1254 # location of GS3's ant build.xml buildfile. Activate.pl can be run from anywhere for GS3 1255 # GSDL3SRCHOME will be set for GS3 by gs3-setup.sh, a step that would have been necessary 1256 # to run the activate.pl script in the first place 1257 1258 my $full_build_xml = &FileUtils::javaFilenameConcatenate($ENV{'GSDL3SRCHOME'},"build.xml"); 1259 1260 my $perl_command = "ant -buildfile \"$full_build_xml\" get-default-servlet-url"; 1261 1262 if (open(PIN, "$perl_command |")) { 1263 while (defined (my $perl_output_line = <PIN>)) { 1264 1265 if($perl_output_line =~ m@http:\/\/(\S*)@) { # grab all the non-whitespace chars 1266 $url="http://".$1; 1267 } 1268 } 1269 close(PIN); 1270 } else { 1271 print STDERR "util::get_library_URL() failed to run $perl_command to work out library URL for $gs_mode\n"; 1272 } 1273 } 1274 1275 # either the url is still undef or it is now set 1276 #print STDERR "\n@@@@@ final URL:|$url|\n" if $url; 1277 #print STDERR "\n@@@@@ URL still undef\n" if !$url; 1278 1279 $ENV{'FULL_GREENSTONE_URL_PREFIX'} = $url; 1280 1281 return $url; 1282 } 1283 1284 1127 1285 # Given a config file (xml or java properties file) and a list/array of regular expressions 1128 1286 # that represent property names to match on, this function will return the value for the 1st
Note:
See TracChangeset
for help on using the changeset viewer.