Changeset 1711


Ignore:
Timestamp:
Mar 9, 2013, 10:20:21 PM (5 years ago)
Author:
bruno
Message:
  • Adds the possibility to prefix the output of commands executed by pb_system, if the verbose keyword is of the form verbose_prefix
File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb-modules/lib/ProjectBuilder/Base.pm

    r1663 r1711  
    135135The first parameter is the shell command to call. This command should NOT use redirections.
    136136The second parameter is the message to print on screen. If none is given, then the command is printed.
    137 The third parameter prints the result of the command after correct execution if value is "verbose". If value is "noredir", it avoids redirecting outputs (e.g. for vi). If value is "quiet", doesn't print anything at all. If value is "mayfail", failure of the command is ok even if $Global::pb_stop_on_error is set, because the caller will be handling the error. A "verbose" can be added to mayfail to have it explain why it failed
     137The third parameter prints the result of the command after correct execution if value is "verbose". If value is "noredir", it avoids redirecting outputs (e.g. for vi). If value is "quiet", doesn't print anything at all. If value is "mayfail", failure of the command is ok even if $Global::pb_stop_on_error is set, because the caller will be handling the error. A "verbose" can be added to mayfail to have it explain why it failed. If value is verbose_PREF, then every output command will be prefixed with PREF.
    138138This function returns as a result the return value of the system command.
    139139
     
    163163    pb_log(0,"NOT OK but non blocking\n") if ($res != 0);
    164164    pb_log(0,"OK\n") if ($res == 0);
    165     pb_display_file("$ENV{'PBTMP'}/system.$$.log") if ((-f "$ENV{'PBTMP'}/system.$$.log") and (defined $verbose) and ($verbose =~ /verbose/));
     165    pb_display_file("$ENV{'PBTMP'}/system.$$.log",undef,$verbose) if ((-f "$ENV{'PBTMP'}/system.$$.log") and (defined $verbose) and ($verbose =~ /verbose/));
    166166    return($res)
    167167}
     
    175175if (defined $error) {
    176176    pb_log(0, $error) if (((! defined $verbose) || ($verbose ne "quiet")) || ($Global::pb_stop_on_error));
    177     pb_display_file("$ENV{'PBTMP'}/system.$$.log") if ((-f "$ENV{'PBTMP'}/system.$$.log") and ((! defined $verbose) || ($verbose ne "quiet") || $Global::pb_stop_on_error));
     177    pb_display_file("$ENV{'PBTMP'}/system.$$.log",undef,$verbose) if ((-f "$ENV{'PBTMP'}/system.$$.log") and ((! defined $verbose) || ($verbose ne "quiet") || $Global::pb_stop_on_error));
    178178    if ($Global::pb_stop_on_error) {
    179179        confess("ERROR running command ($cmd) with cwd=$cwd, pid=$$");
     
    183183} else {
    184184    pb_log(0,"OK\n") if ((! defined $verbose) || ($verbose ne "quiet"));
    185     pb_display_file("$ENV{'PBTMP'}/system.$$.log") if ((-f "$ENV{'PBTMP'}/system.$$.log") and (defined $verbose) and ($verbose ne "quiet"));
     185    pb_display_file("$ENV{'PBTMP'}/system.$$.log",undef,$verbose) if ((-f "$ENV{'PBTMP'}/system.$$.log") and (defined $verbose) and ($verbose ne "quiet"));
    186186}
    187187
     
    290290=item B<pb_display_file>
    291291
    292 This function print the content of the file passed in parameter.
     292This function prints the content of the file passed in parameter.
    293293If a second parameter is given, this is the descriptor of the logfile to write to in addtion to STDOUT.
     294If a third parameter is given, this is the prefix providing it's writen as verbose_PREF. In which case the PREF string will be added before the line output.
    294295
    295296This is a cat equivalent function.
     
    301302my $file=shift;
    302303my $desc=shift || undef;
     304my $prefix=shift;
    303305
    304306return if (not -f $file);
    305307my $cnt = pb_get_content($file);
    306 print "$cnt\n";
    307 print $desc "$cnt\n" if (defined $desc);
     308# If we have a prefix, then add it at each line
     309if ((defined $prefix) and ($prefix =~ "_")) {
     310    $prefix =~ s/verbose_//;
     311    $cnt =~ s/\n/\n$prefix/g;
     312} else {
     313    $prefix = "";
     314}
     315print "$prefix$cnt\n";
     316print $desc "$prefix$cnt\n" if (defined $desc);
    308317}
    309318
Note: See TracChangeset for help on using the changeset viewer.