jl165 merging heads
[LibreOffice.git] / testgraphical / source / filehelper.pm
blobed1be35cf124a0acfc128cdbaf5ec24e43ff5e20
1 package filehelper;
3 #*************************************************************************
5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 # Copyright 2000, 2010 Oracle and/or its affiliates.
9 # OpenOffice.org - a multi-platform office productivity suite
11 # This file is part of OpenOffice.org.
13 # OpenOffice.org is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU Lesser General Public License version 3
15 # only, as published by the Free Software Foundation.
17 # OpenOffice.org 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 Lesser General Public License version 3 for more details
21 # (a copy is included in the LICENSE file that accompanied this code).
23 # You should have received a copy of the GNU Lesser General Public License
24 # version 3 along with OpenOffice.org. If not, see
25 # <http://www.openoffice.org/license.html>
26 # for a copy of the LGPLv3 License.
28 #*************************************************************************
30 use strict;
31 use warnings;
32 use strict;
33 use English; # $OSNAME, ...
34 use stringhelper;
36 BEGIN {
37 use Exporter ();
38 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
40 $VERSION = 1.00;
41 # if using RCS/CVS, this may be preferred
42 $VERSION = do { my @r = (q$Revision: 1.1 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker
43 @ISA = qw(Exporter);
44 @EXPORT = qw(&dospath &unixpath &appendPath &appendClass &setPrefix &getToolsPrefix &rmkdir &getJavaPathSeparator &getJavaFileDirSeparator &getFromPathes &convertCygwinPath);
45 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
46 # your exported package globals go here,
47 # as well as any optionally exported functions
48 @EXPORT_OK = ( ); # qw($Var1 %Hashit &func3);
52 # ------------------------------------------------------------------------------
53 # helper, to change all file separators
54 sub dospath($)
56 my $sPath = shift;
57 if ($OSNAME eq "MSWin32")
59 # make out of '/' a '\'
60 $sPath =~ s/\//\\/g;
62 else
65 return $sPath;
68 sub unixpath($)
70 my $sPath = shift;
71 if ($OSNAME ne "MSWin32")
73 # make out of '\' a '/'
74 $sPath =~ s/\\/\//g;
76 else
79 return $sPath;
82 # ------------------------------------------------------------------------------
83 # sub getGlobalInstSet()
84 # {
85 # my $sJumbo;
86 # if ($OSNAME eq "MSWin32")
87 # {
88 # # $sJumbo = "\\\\so-gfxcmp-lin\\jumbo_ship\\install";
89 # $sJumbo = "\\\\jumbo.germany.sun.com\\ship\\install";
90 # }
91 # elsif ($OSNAME eq "cygwin")
92 # {
93 # $sJumbo = "//jumbo.germany.sun.com/ship/install";
94 # }
95 # else
96 # {
97 # $sJumbo = "/net/jumbo.germany.sun.com/ship/install";
98 # }
99 # return $sJumbo;
102 # ------------------------------------------------------------------------------
103 # sub getSolarisLockFile()
105 # my $sSolarisLockFile = "/tmp/.ai.pkg.zone.lock-afdb66cf-1dd1-11b2-a049-000d560ddc3e";
106 # return $sSolarisLockFile;
109 # sub checkForSolarisLock()
111 # if ($OSNAME eq "solaris")
113 # # wait until the internal installer lock is gone
114 # while ( -e getSolarisLockFile() )
116 # while ( -e getSolarisLockFile() )
118 # log_print( "Warning: Wait active until installer lock is gone. \n");
119 # sleep 1;
121 # sleep 5;
123 # log_print( "[ok], lock is gone.\n");
127 # sub deleteSolarisLock()
129 # if ($OSNAME eq "solaris")
131 # sleep 1;
132 # unlink getSolarisLockFile();
134 # sleep 1;
135 # if ( -e getSolarisLockFile() )
137 # # try delete the file as super user?
138 # `sudo rm -f getSolarisLockFile()`;
139 # sleep 1;
144 # ------------------------------------------------------------------------------
145 sub appendPath($$)
147 my $sPath = shift;
148 my $sAddPath = shift;
149 if ($sPath && $sAddPath)
151 if (! endswith($sPath, "/") &&
152 ! endswith($sPath, "\\"))
154 # getJavaFileDirSeparator();
155 $sPath .= "/";
157 $sPath .= $sAddPath;
159 return $sPath;
162 sub appendClass($$)
164 my $sPath = shift;
165 my $sAddPath = shift;
167 my $sSeparator = getJavaPathSeparator();
168 if ($sPath && $sAddPath)
170 if (! endswith($sPath, $sSeparator))
172 # getJavaFileDirSeparator();
173 $sPath .= $sSeparator;
175 $sPath .= $sAddPath;
177 return $sPath;
180 # ------------------------------------------------------------------------------
182 our $sPrefix;
183 sub setPrefix($)
185 $sPrefix = shift;
188 sub getPrefix()
190 return $sPrefix;
193 # ------------------------------------------------------------------------------
194 our $programprefix;
196 # sub getProgramPrefix($)
198 # my $sDBDistinct = shift;
200 # my $sProgramPrefix;
201 # if (! $programprefix)
203 # if ($OSNAME eq "MSWin32")
205 # # $programprefix = "C:/gfxcmp/programs";
206 # $programprefix = "C:";
207 # if (getPrefix() eq "performance")
209 # $programprefix = "D:";
211 # $programprefix = appendPath($programprefix, "gp");
213 # elsif ($OSNAME eq "linux")
215 # $programprefix = "/space/" . getPrefix() . "/programs";
217 # elsif ($OSNAME eq "solaris")
219 # $programprefix = "/space/" . getPrefix() . "/programs";
221 # else
223 # print "Error: This environment isn't supported yet.\n";
224 # exit(1);
227 # $sProgramPrefix = appendPath($programprefix, substr($sDBDistinct, 0, 19));
228 # return $sProgramPrefix;
230 # ------------------------------------------------------------------------------
231 our $toolsprefix;
233 sub getToolsPrefix()
235 my $sToolsPrefix;
236 if (! $toolsprefix)
238 if ($OSNAME eq "MSWin32")
240 $toolsprefix = "C:";
241 if (getPrefix() eq "performance")
243 $toolsprefix = "D:";
246 elsif ($OSNAME eq "linux")
248 $toolsprefix = "/space";
250 elsif ($OSNAME eq "solaris")
252 $toolsprefix = "/space";
254 else
256 print "Error: This environment isn't supported yet.\n";
257 exit(1);
259 $toolsprefix = appendPath($toolsprefix, getPrefix());
260 $toolsprefix = appendPath($toolsprefix, "tools");
262 $sToolsPrefix = $toolsprefix;
263 return $sToolsPrefix;
266 # also Windows safe
267 sub rmkdir($)
269 my($tpath) = shift;
270 my $dir;
271 my $accum = "";
273 my @dirs = split(/\//, $tpath);
274 if ( $#dirs eq 0 )
276 @dirs = split("\\\\", $tpath);
279 foreach $dir (@dirs)
281 $accum = "$accum$dir/";
282 if($dir ne "")
284 if(! -d "$accum")
286 mkdir ($accum);
287 chmod (0777,$accum);
293 # ------------------------------------------------------------------------------
294 sub getJavaPathSeparator()
296 my $ps = ":";
297 if ($OSNAME eq "MSWin32" || $OSNAME eq "cygwin")
299 $ps = ";";
301 return $ps;
303 # ------------------------------------------------------------------------------
304 sub getJavaFileDirSeparator()
306 my $sfs = "/";
307 if ($OSNAME eq "MSWin32")
309 $sfs = "\\";
311 return $sfs;
313 # ------------------------------------------------------------------------------
314 sub getFromPathes($$)
316 my $sPathesIni = shift;
317 my $searchvalue = shift;
318 my $sResult;
319 if ( -e $sPathesIni)
321 local *PATHES;
322 if (open(PATHES, "$sPathesIni"))
324 my $line;
325 while ($line = <PATHES>)
327 chomp($line);
328 if ($line =~ /^$searchvalue=(.*)$/)
330 $sResult = $1;
333 close(PATHES);
336 return $sResult;
339 sub convertCygwinPath($)
341 my $sPath = shift;
343 if ($OSNAME eq "cygwin")
345 # print "Cygwin Path Patch.\n" if ($verbose);
346 if ($sPath =~ /\/cygdrive\/(.)/)
348 my $Letter = $1;
349 $sPath =~ s/\/cygdrive\/${Letter}/${Letter}\:/;
350 # print "Cygwin Path Patch: '$sPath'\n" if ($verbose);
353 return $sPath;