[2] | 1 | #!/usr/bin/perl -w
|
---|
| 2 | #
|
---|
[395] | 3 | # Base subroutines brought by the the Project-Builder project
|
---|
| 4 | # which can be easily used by whatever perl project
|
---|
[2] | 5 | #
|
---|
[395] | 6 | # Copyright B. Cornec 2007-2008
|
---|
| 7 | # Provided under the GPL v2
|
---|
| 8 | #
|
---|
[2] | 9 | # $Id$
|
---|
| 10 | #
|
---|
| 11 |
|
---|
[318] | 12 | package ProjectBuilder::Base;
|
---|
| 13 |
|
---|
[18] | 14 | use strict;
|
---|
[5] | 15 | use lib qw (lib);
|
---|
[9] | 16 | use File::Path;
|
---|
[318] | 17 | use File::Temp qw(tempdir);
|
---|
[8] | 18 | use Data::Dumper;
|
---|
[318] | 19 | use Time::localtime qw(localtime);
|
---|
[397] | 20 | use Pod::Usage;
|
---|
[328] | 21 | use English;
|
---|
[681] | 22 | use POSIX qw(locale_h);
|
---|
[1148] | 23 | use ProjectBuilder::Version;
|
---|
[2] | 24 |
|
---|
[318] | 25 | # Inherit from the "Exporter" module which handles exporting functions.
|
---|
| 26 |
|
---|
[1156] | 27 | use vars qw($VERSION $REVISION @ISA @EXPORT);
|
---|
[318] | 28 | use Exporter;
|
---|
| 29 |
|
---|
| 30 | # Export, by default, all the functions into the namespace of
|
---|
| 31 | # any code which uses this module.
|
---|
| 32 |
|
---|
[495] | 33 | our $pbdebug = 0; # Global debug level
|
---|
| 34 | our $pbLOG = \*STDOUT; # File descriptor of the log file
|
---|
| 35 | our $pbsynmsg = "Error"; # Global error message
|
---|
| 36 | our $pbdisplaytype = "text";
|
---|
| 37 | # default display mode for messages
|
---|
| 38 | our $pblocale = "C";
|
---|
[318] | 39 |
|
---|
| 40 | our @ISA = qw(Exporter);
|
---|
[1127] | 41 | our @EXPORT = qw(pb_mkdir_p pb_system pb_rm_rf pb_get_date pb_log pb_log_init pb_get_uri pb_get_content pb_set_content pb_display_file pb_syntax_init pb_syntax pb_temp_init pb_get_arch pb_check_requirements pb_check_req $pbdebug $pbLOG $pbdisplaytype $pblocale);
|
---|
[1156] | 42 | ($VERSION,$REVISION) = pb_version_init();
|
---|
[318] | 43 |
|
---|
[395] | 44 | =pod
|
---|
[2] | 45 |
|
---|
[395] | 46 | =head1 NAME
|
---|
[2] | 47 |
|
---|
[395] | 48 | ProjectBuilder::Base, part of the project-builder.org - module dealing with generic functions suitable for perl project development
|
---|
[355] | 49 |
|
---|
[395] | 50 | =head1 DESCRIPTION
|
---|
[69] | 51 |
|
---|
[395] | 52 | This modules provides generic functions suitable for perl project development
|
---|
[69] | 53 |
|
---|
[395] | 54 | =head1 SYNOPSIS
|
---|
[69] | 55 |
|
---|
[395] | 56 | use ProjectBuilder::Base;
|
---|
[313] | 57 |
|
---|
[395] | 58 | #
|
---|
| 59 | # Create a directory and its parents
|
---|
| 60 | #
|
---|
| 61 | pb_mkdir_p("/tmp/foo/bar");
|
---|
[313] | 62 |
|
---|
[395] | 63 | #
|
---|
| 64 | # Remove recursively a directory and its children
|
---|
| 65 | #
|
---|
| 66 | pb_rm_rf("/tmp/foo");
|
---|
[313] | 67 |
|
---|
[395] | 68 | #
|
---|
| 69 | # Encapsulate the system call for better output and return value test
|
---|
| 70 | #
|
---|
| 71 | pb_system("ls -l", "Printing directory content");
|
---|
[314] | 72 |
|
---|
[395] | 73 | #
|
---|
| 74 | # Analysis a URI and return its components in a table
|
---|
| 75 | #
|
---|
[1076] | 76 | my ($scheme, $account, $host, $port, $path) = pb_get_uri("svn+ssh://ac@my.server.org:port/path/to/dir");
|
---|
[313] | 77 |
|
---|
[395] | 78 | #
|
---|
| 79 | # Gives the current date in a table
|
---|
| 80 | #
|
---|
| 81 | @date = pb_get_date();
|
---|
[2] | 82 |
|
---|
[395] | 83 | #
|
---|
| 84 | # Manages logs of the program
|
---|
| 85 | #
|
---|
| 86 | pb_log_init(2,\*STDOUT);
|
---|
| 87 | pb_log(1,"Message to print\n");
|
---|
[313] | 88 |
|
---|
[395] | 89 | #
|
---|
| 90 | # Manages content of a file
|
---|
| 91 | #
|
---|
[1063] | 92 | pb_display_file("/etc/passwd",\*STDERR);
|
---|
[395] | 93 | my $cnt = pb_get_content("/etc/passwd");
|
---|
[313] | 94 |
|
---|
[395] | 95 | =head1 USAGE
|
---|
[320] | 96 |
|
---|
[395] | 97 | =over 4
|
---|
[323] | 98 |
|
---|
[395] | 99 | =item B<pb_mkdir_p>
|
---|
[314] | 100 |
|
---|
[395] | 101 | Internal mkdir -p function. Forces mode to 755. Supports multiple parameters.
|
---|
[358] | 102 |
|
---|
[396] | 103 | Based on File::Path mkpath.
|
---|
| 104 |
|
---|
[395] | 105 | =cut
|
---|
[273] | 106 |
|
---|
[74] | 107 | sub pb_mkdir_p {
|
---|
[29] | 108 | my @dir = @_;
|
---|
| 109 | my $ret = mkpath(@dir, 0, 0755);
|
---|
| 110 | return($ret);
|
---|
[9] | 111 | }
|
---|
| 112 |
|
---|
[396] | 113 | =item B<pb_rm_rf>
|
---|
[395] | 114 |
|
---|
| 115 | Internal rm -rf function. Supports multiple parameters.
|
---|
| 116 |
|
---|
[396] | 117 | Based on File::Path rmtree.
|
---|
| 118 |
|
---|
[395] | 119 | =cut
|
---|
| 120 |
|
---|
[74] | 121 | sub pb_rm_rf {
|
---|
[29] | 122 | my @dir = @_;
|
---|
| 123 | my $ret = rmtree(@dir, 0, 0);
|
---|
| 124 | return($ret);
|
---|
[9] | 125 | }
|
---|
| 126 |
|
---|
[395] | 127 | =item B<pb_system>
|
---|
| 128 |
|
---|
| 129 | Encapsulate the "system" call for better output and return value test
|
---|
| 130 | Needs a $ENV{'PBTMP'} variable which is created by calling the pb_mktemp_init function
|
---|
| 131 | Needs pb_log support, so pb_log_init should have benn called before.
|
---|
| 132 |
|
---|
| 133 | The first parameter is the shell command to call.
|
---|
| 134 | The second parameter is the message to print on screen. If none is given, then the command is printed.
|
---|
[473] | 135 | The third parameter print the result of the command after correct execution if value is verbose. If value is noredir, it avoids redirecting outputs (e.g. for vi).
|
---|
[395] | 136 | This function returns the result the return value of the system command.
|
---|
[396] | 137 |
|
---|
[395] | 138 | If no error reported, it prints OK on the screen, just after the message. Else it prints the errors generated.
|
---|
| 139 |
|
---|
| 140 | =cut
|
---|
| 141 |
|
---|
[74] | 142 | sub pb_system {
|
---|
[29] | 143 |
|
---|
| 144 | my $cmd=shift;
|
---|
[30] | 145 | my $cmt=shift || $cmd;
|
---|
[471] | 146 | my $verbose=shift || undef;
|
---|
[473] | 147 | my $redir = "";
|
---|
[29] | 148 |
|
---|
[503] | 149 | pb_log(0,"$cmt... ") if ((! defined $verbose) || ($verbose ne "quiet"));
|
---|
[395] | 150 | pb_log(1,"Executing $cmd\n");
|
---|
[1137] | 151 | unlink("$ENV{'PBTMP'}/system.$$.log") if (-f "$ENV{'PBTMP'}/system.$$.log");
|
---|
| 152 | $redir = "2>> $ENV{'PBTMP'}/system.$$.log 1>> $ENV{'PBTMP'}/system.$$.log" if ((! defined $verbose) || ($verbose ne "noredir"));
|
---|
[473] | 153 | system("$cmd $redir");
|
---|
[347] | 154 | my $res = $?;
|
---|
[500] | 155 | # Exit now if the command may fail
|
---|
| 156 | if ((defined $verbose) and ($verbose eq "mayfail")) {
|
---|
| 157 | pb_log(0,"N/A\n") if ($res != 0);
|
---|
| 158 | pb_log(0,"OK\n") if ($res == 0);
|
---|
| 159 | return($res)
|
---|
| 160 | }
|
---|
[347] | 161 | if ($res == -1) {
|
---|
[503] | 162 | pb_log(0,"failed to execute ($cmd): $!\n") if ((! defined $verbose) || ($verbose ne "quiet"));
|
---|
[1137] | 163 | pb_display_file("$ENV{'PBTMP'}/system.$$.log") if ((-f "$ENV{'PBTMP'}/system.$$.log") and ((! defined $verbose) || ($verbose ne "quiet")));
|
---|
[347] | 164 | } elsif ($res & 127) {
|
---|
[503] | 165 | pb_log(0, "child ($cmd) died with signal ".($? & 127).", ".($? & 128) ? 'with' : 'without'." coredump\n") if ((! defined $verbose) || ($verbose ne "quiet"));
|
---|
[1137] | 166 | pb_display_file("$ENV{'PBTMP'}/system.$$.log") if ((-f "$ENV{'PBTMP'}/system.$$.log") and ((! defined $verbose) || ($verbose ne "quiet")));
|
---|
[347] | 167 | } elsif ($res == 0) {
|
---|
[503] | 168 | pb_log(0,"OK\n") if ((! defined $verbose) || ($verbose ne "quiet"));
|
---|
[1137] | 169 | pb_display_file("$ENV{'PBTMP'}/system.$$.log") if ((defined $verbose) and (-f "$ENV{'PBTMP'}/system.$$.log") and ($verbose ne "quiet"));
|
---|
[29] | 170 | } else {
|
---|
[503] | 171 | pb_log(0, "child ($cmd) exited with value ".($? >> 8)."\n") if ((! defined $verbose) || ($verbose ne "quiet"));
|
---|
[1137] | 172 | pb_display_file("$ENV{'PBTMP'}/system.$$.log") if ((-f "$ENV{'PBTMP'}/system.$$.log") and ((! defined $verbose) || ($verbose ne "quiet")));
|
---|
[29] | 173 | }
|
---|
[347] | 174 | return($res);
|
---|
[30] | 175 | }
|
---|
[74] | 176 |
|
---|
[395] | 177 | =item B<pb_get_uri>
|
---|
| 178 |
|
---|
| 179 | This function returns a list of 6 parameters indicating the protocol, account, password, server, port, and path contained in the URI passed in parameter.
|
---|
| 180 |
|
---|
| 181 | A URI has the format protocol://[ac@]host[:port][path[?query][#fragment]].
|
---|
[396] | 182 |
|
---|
[395] | 183 | Cf man URI.
|
---|
| 184 |
|
---|
| 185 | =cut
|
---|
| 186 |
|
---|
[314] | 187 | sub pb_get_uri {
|
---|
[313] | 188 |
|
---|
[314] | 189 | my $uri = shift || undef;
|
---|
[313] | 190 |
|
---|
[318] | 191 | pb_log(2,"DEBUG: uri:$uri\n");
|
---|
[314] | 192 | my ($scheme, $authority, $path, $query, $fragment) =
|
---|
[318] | 193 | $uri =~ m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?| if (defined $uri);
|
---|
| 194 | my ($account,$host,$port) = $authority =~ m|(?:([^\@]+)\@)?([^:]+)(:(?:[0-9]+))?| if (defined $authority);
|
---|
| 195 |
|
---|
| 196 | $scheme = "" if (not defined $scheme);
|
---|
| 197 | $authority = "" if (not defined $authority);
|
---|
| 198 | $path = "" if (not defined $path);
|
---|
| 199 | $account = "" if (not defined $account);
|
---|
| 200 | $host = "" if (not defined $host);
|
---|
[1076] | 201 | if (not defined $port) {
|
---|
| 202 | $port = ""
|
---|
| 203 | } else {
|
---|
| 204 | # Remove extra : at start
|
---|
| 205 | $port =~ s/^://;
|
---|
| 206 | }
|
---|
[318] | 207 |
|
---|
[315] | 208 | pb_log(2,"DEBUG: scheme:$scheme ac:$account host:$host port:$port path:$path\n");
|
---|
[314] | 209 | return($scheme, $account, $host, $port, $path);
|
---|
[313] | 210 | }
|
---|
| 211 |
|
---|
[395] | 212 | =item B<pb_get_date>
|
---|
[313] | 213 |
|
---|
[395] | 214 | This function returns a list of 9 parameters indicating the seconds, minutes, hours, day, month, year, day in the week, day in the year, and daylight saving time flag of the current time.
|
---|
[74] | 215 |
|
---|
[395] | 216 | Cf: man ctime and description of the struct tm.
|
---|
[74] | 217 |
|
---|
[395] | 218 | =cut
|
---|
[339] | 219 |
|
---|
[315] | 220 | sub pb_get_date {
|
---|
| 221 |
|
---|
| 222 | return(localtime->sec(), localtime->min(), localtime->hour(), localtime->mday(), localtime->mon(), localtime->year(), localtime->wday(), localtime->yday(), localtime->isdst());
|
---|
| 223 | }
|
---|
| 224 |
|
---|
[395] | 225 | =item B<pb_log_init>
|
---|
[315] | 226 |
|
---|
[395] | 227 | This function initializes the global variables used by the pb_log function.
|
---|
[106] | 228 |
|
---|
[395] | 229 | The first parameter is the debug level which will be considered during the run of the program?
|
---|
| 230 | The second parameter is a pointer on a file descriptor used to print the log info.
|
---|
[315] | 231 |
|
---|
[396] | 232 | As an example, if you set the debug level to 2 in that function, every call to pb_log which contains a value less or equal than 2 will be printed. Calls with a value greater than 2 won't be printed.
|
---|
| 233 |
|
---|
| 234 | The call to B<pb_log_init> is typically done after getting a parameter on the CLI indicating the level of verbosity expected.
|
---|
| 235 |
|
---|
[395] | 236 | =cut
|
---|
[319] | 237 |
|
---|
[315] | 238 | sub pb_log_init {
|
---|
[77] | 239 |
|
---|
[495] | 240 | $pbdebug = shift || 0;
|
---|
| 241 | $pbLOG = shift || \*STDOUT;
|
---|
| 242 | pb_log(1,"Debug value: $pbdebug\n");
|
---|
[315] | 243 |
|
---|
| 244 | }
|
---|
| 245 |
|
---|
[396] | 246 | =item B<pb_log>
|
---|
| 247 |
|
---|
| 248 | This function logs the messages passed as the second parameter if the value passed as first parameter is lesser or equal than the value passed to the B<pb_log_init> function.
|
---|
| 249 |
|
---|
| 250 | Here is a usage example:
|
---|
| 251 |
|
---|
| 252 | pb_log_init(2,\*STDERR);
|
---|
| 253 | pb_log(1,"Hello World 1\n");
|
---|
| 254 | pb_log(2,"Hello World 2\n");
|
---|
| 255 | pb_log(3,"Hello World 3\n");
|
---|
| 256 |
|
---|
| 257 | will print:
|
---|
| 258 |
|
---|
| 259 | Hello World 1
|
---|
| 260 | Hello World 2
|
---|
| 261 |
|
---|
| 262 | =cut
|
---|
| 263 |
|
---|
[315] | 264 | sub pb_log {
|
---|
| 265 |
|
---|
| 266 | my $dlevel = shift;
|
---|
| 267 | my $msg = shift;
|
---|
| 268 |
|
---|
[495] | 269 | print $pbLOG "$msg" if ($dlevel <= $pbdebug);
|
---|
[1060] | 270 | print "$msg" if (($dlevel == 0) && ($pbLOG != \*STDOUT));
|
---|
[315] | 271 | }
|
---|
| 272 |
|
---|
[495] | 273 |
|
---|
[396] | 274 | =item B<pb_display_file>
|
---|
| 275 |
|
---|
| 276 | This function print the content of the file passed in parameter.
|
---|
[1063] | 277 | If a second parameter is given, this is the descriptor of the logfile to write to in addtion to STDOUT.
|
---|
[396] | 278 |
|
---|
| 279 | This is a cat equivalent function.
|
---|
| 280 |
|
---|
| 281 | =cut
|
---|
| 282 |
|
---|
[395] | 283 | sub pb_display_file {
|
---|
[316] | 284 |
|
---|
[395] | 285 | my $file=shift;
|
---|
[1063] | 286 | my $desc=shift || undef;
|
---|
[316] | 287 |
|
---|
[395] | 288 | return if (not -f $file);
|
---|
[1063] | 289 | my $cnt = pb_get_content($file);
|
---|
| 290 | print "$cnt\n";
|
---|
| 291 | print $desc "$cnt\n" if (defined $desc);
|
---|
[316] | 292 | }
|
---|
| 293 |
|
---|
[396] | 294 | =item B<pb_get_content>
|
---|
| 295 |
|
---|
| 296 | This function returns the content of the file passed in parameter.
|
---|
| 297 |
|
---|
| 298 | =cut
|
---|
| 299 |
|
---|
[395] | 300 | sub pb_get_content {
|
---|
[353] | 301 |
|
---|
[395] | 302 | my $file=shift;
|
---|
[353] | 303 |
|
---|
[395] | 304 | my $bkp = $/;
|
---|
| 305 | undef $/;
|
---|
| 306 | open(R,$file) || die "Unable to open $file: $!";
|
---|
| 307 | my $content=<R>;
|
---|
| 308 | close(R);
|
---|
| 309 | chomp($content);
|
---|
| 310 | $/ = $bkp;
|
---|
| 311 | return($content);
|
---|
[353] | 312 | }
|
---|
| 313 |
|
---|
[556] | 314 |
|
---|
| 315 | =item B<pb_set_content>
|
---|
| 316 |
|
---|
[1137] | 317 | This function put the content of a variable passed as second parameter into the file passed as first parameter.
|
---|
[556] | 318 |
|
---|
| 319 | =cut
|
---|
| 320 |
|
---|
| 321 | sub pb_set_content {
|
---|
| 322 |
|
---|
| 323 | my $file=shift;
|
---|
| 324 | my $content=shift;
|
---|
| 325 |
|
---|
| 326 | my $bkp = $/;
|
---|
| 327 | undef $/;
|
---|
| 328 | open(R,"> $file") || die "Unable to write to $file: $!";
|
---|
| 329 | print R "$content";
|
---|
| 330 | close(R);
|
---|
| 331 | $/ = $bkp;
|
---|
| 332 | }
|
---|
| 333 |
|
---|
[397] | 334 | =item B<pb_syntax_init>
|
---|
| 335 |
|
---|
| 336 | This function initializes the global variable used by the pb_syntax function.
|
---|
| 337 |
|
---|
| 338 | The parameter is the message string which will be printed when calling pb_syntax
|
---|
| 339 |
|
---|
| 340 | =cut
|
---|
| 341 |
|
---|
| 342 | sub pb_syntax_init {
|
---|
| 343 |
|
---|
[495] | 344 | $pbsynmsg = shift || "Error";
|
---|
[397] | 345 | }
|
---|
| 346 |
|
---|
| 347 | =item B<pb_syntax>
|
---|
| 348 |
|
---|
| 349 | This function prints the syntax expected by the application, based on pod2usage, and exits.
|
---|
| 350 | The first parameter is the return value of the exit.
|
---|
| 351 | The second parameter is the verbosity as expected by pod2usage.
|
---|
| 352 |
|
---|
| 353 | Cf: man Pod::Usage
|
---|
| 354 |
|
---|
| 355 | =cut
|
---|
| 356 |
|
---|
| 357 | sub pb_syntax {
|
---|
| 358 |
|
---|
| 359 | my $exit_status = shift || -1;
|
---|
| 360 | my $verbose_level = shift || 0;
|
---|
| 361 |
|
---|
| 362 | my $filehandle = \*STDERR;
|
---|
| 363 |
|
---|
| 364 | $filehandle = \*STDOUT if ($exit_status == 0);
|
---|
| 365 |
|
---|
[495] | 366 | pod2usage( { -message => $pbsynmsg,
|
---|
[397] | 367 | -exitval => $exit_status ,
|
---|
| 368 | -verbose => $verbose_level,
|
---|
| 369 | -output => $filehandle } );
|
---|
| 370 | }
|
---|
| 371 |
|
---|
| 372 | =item B<pb_temp_init>
|
---|
| 373 |
|
---|
| 374 | This function initializes the environemnt variable PBTMP to a random value. This directory can be safely used during the whole program, it will be removed at the end automatically.
|
---|
| 375 |
|
---|
| 376 | =cut
|
---|
| 377 |
|
---|
| 378 | sub pb_temp_init {
|
---|
| 379 |
|
---|
| 380 | if (not defined $ENV{'TMPDIR'}) {
|
---|
| 381 | $ENV{'TMPDIR'}="/tmp";
|
---|
| 382 | }
|
---|
| 383 | $ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
|
---|
| 384 | }
|
---|
| 385 |
|
---|
[749] | 386 | =item B<pb_get_arch>
|
---|
| 387 |
|
---|
| 388 | This function returns the architecture of our local environment and
|
---|
| 389 | standardize on i386 for those platforms. It also solves issues where a i386 VE on x86_64 returns x86_64 wrongly
|
---|
| 390 |
|
---|
| 391 | =cut
|
---|
| 392 |
|
---|
| 393 | sub pb_get_arch {
|
---|
| 394 |
|
---|
| 395 | my $arch = `uname -m`;
|
---|
| 396 | chomp($arch);
|
---|
| 397 | $arch =~ s/i.86/i386/;
|
---|
[873] | 398 | # For Solaris
|
---|
| 399 | $arch =~ s/i86pc/i386/;
|
---|
[749] | 400 |
|
---|
| 401 | return($arch);
|
---|
| 402 | }
|
---|
| 403 |
|
---|
[974] | 404 | =item B<pb_check_requirements>
|
---|
| 405 |
|
---|
| 406 | This function checks that the commands needed for the subsystem are indeed present.
|
---|
[1077] | 407 | The required commands are passed as a coma separated string as first parameter.
|
---|
| 408 | The optional commands are passed as a coma separated string as second parameter.
|
---|
[974] | 409 |
|
---|
| 410 | =cut
|
---|
| 411 |
|
---|
| 412 | sub pb_check_requirements {
|
---|
| 413 |
|
---|
[1128] | 414 | my $req = shift || undef;
|
---|
| 415 | my $opt = shift || undef;
|
---|
| 416 | my $appname = shift || undef;
|
---|
[974] | 417 |
|
---|
[1128] | 418 | my ($req2,$opt2) = (undef,undef);
|
---|
| 419 | $req2 = $req->{$appname} if (defined $req and defined $appname);
|
---|
| 420 | $opt2 = $opt->{$appname} if (defined $opt and defined $appname);
|
---|
| 421 |
|
---|
[974] | 422 | # cmds is a string of coma separated commands
|
---|
[1128] | 423 | if (defined $req2) {
|
---|
| 424 | foreach my $file (split(/,/,$req2)) {
|
---|
| 425 | pb_check_req($file,0);
|
---|
| 426 | }
|
---|
[974] | 427 | }
|
---|
| 428 |
|
---|
| 429 | # opts is a string of coma separated commands
|
---|
[1128] | 430 | if (defined $opt2) {
|
---|
| 431 | foreach my $file (split(/,/,$opt2)) {
|
---|
| 432 | pb_check_req($file,1);
|
---|
| 433 | }
|
---|
[974] | 434 | }
|
---|
| 435 | }
|
---|
| 436 |
|
---|
[1127] | 437 | =item B<pb_check_req>
|
---|
| 438 |
|
---|
| 439 | This function checks existence of a command and return its full pathname.
|
---|
| 440 | The command name is passed as first parameter.
|
---|
| 441 | The second parameter should be 0 if the command is mandatory, 1 if optional.
|
---|
| 442 |
|
---|
| 443 | =cut
|
---|
| 444 |
|
---|
[974] | 445 | sub pb_check_req {
|
---|
| 446 |
|
---|
| 447 | my $file = shift;
|
---|
| 448 | my $opt = shift || 1;
|
---|
[1127] | 449 | my $found = undef;
|
---|
[974] | 450 |
|
---|
| 451 | pb_log(2,"Checking availability of $file...");
|
---|
| 452 | # Check for all dirs in the PATH
|
---|
| 453 | foreach my $p (split(/:/,$ENV{'PATH'})) {
|
---|
[1127] | 454 | if (-x "$p/$file") {
|
---|
| 455 | $found = "$p/$file";
|
---|
| 456 | last;
|
---|
| 457 | }
|
---|
[974] | 458 | }
|
---|
[1127] | 459 |
|
---|
| 460 | if (not $found) {
|
---|
[974] | 461 | pb_log(2,"KO\n");
|
---|
| 462 | if ($opt eq 1) {
|
---|
| 463 | pb_log(2,"Unable to find optional command $file\n");
|
---|
| 464 | } else {
|
---|
| 465 | die pb_log(0,"Unable to find required command $file\n");
|
---|
| 466 | }
|
---|
| 467 | } else {
|
---|
| 468 | pb_log(2,"OK\n");
|
---|
[1128] | 469 | return($found);
|
---|
[974] | 470 | }
|
---|
| 471 | }
|
---|
| 472 |
|
---|
[397] | 473 | =back
|
---|
| 474 |
|
---|
| 475 | =head1 WEB SITES
|
---|
| 476 |
|
---|
| 477 | The main Web site of the project is available at L<http://www.project-builder.org/>. Bug reports should be filled using the trac instance of the project at L<http://trac.project-builder.org/>.
|
---|
| 478 |
|
---|
| 479 | =head1 USER MAILING LIST
|
---|
| 480 |
|
---|
| 481 | None exists for the moment.
|
---|
| 482 |
|
---|
| 483 | =head1 AUTHORS
|
---|
| 484 |
|
---|
| 485 | The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
|
---|
| 486 |
|
---|
| 487 | =head1 COPYRIGHT
|
---|
| 488 |
|
---|
| 489 | Project-Builder.org is distributed under the GPL v2.0 license
|
---|
| 490 | described in the file C<COPYING> included with the distribution.
|
---|
| 491 |
|
---|
| 492 | =cut
|
---|
| 493 |
|
---|
[2] | 494 | 1;
|
---|