[Bio] / FigKernelPackages / Tracer.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/Tracer.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.39, Fri Feb 24 19:45:29 2006 UTC revision 1.43, Mon Apr 24 21:05:17 2006 UTC
# Line 275  Line 275 
275  of a keyword, the value is separated from the option name by an equal sign. You  of a keyword, the value is separated from the option name by an equal sign. You
276  can see this last in the command-line example above.  can see this last in the command-line example above.
277    
278    You can specify a different default trace level by setting C<$options->{trace}>
279    prior to calling this method.
280    
281  An example at this point would help. Consider, for example, the command-line utility  An example at this point would help. Consider, for example, the command-line utility
282  C<TransactFeatures>. It accepts a list of positional parameters plus the options  C<TransactFeatures>. It accepts a list of positional parameters plus the options
283  C<safe>, C<noAlias>, C<start>, and C<tblFiles>. To start up this command, we execute  C<safe>, C<noAlias>, C<start>, and C<tblFiles>. To start up this command, we execute
# Line 314  Line 317 
317  need to be added in the future, they can be processed by this method without  need to be added in the future, they can be processed by this method without
318  upsetting the command-line utilities.  upsetting the command-line utilities.
319    
320    If the C<background> option is specified on the command line, then the
321    standard and error outputs will be directed to files in the temporary
322    directory, using the same suffix as the trace file. So, if the command
323    line specified
324    
325        -user=Bruce -background
326    
327    then the trace output would go to C<traceBruce.log>, the standard output to
328    C<outBruce.log>, and the error output to C<errBruce.log>. This is designed to
329    simplify starting a command in the background.
330    
331  Finally, if the special option C<-h> is specified, the option names will  Finally, if the special option C<-h> is specified, the option names will
332  be traced at level 0 and the program will exit without processing.  be traced at level 0 and the program will exit without processing.
333  This provides a limited help capability. For example, if the user enters  This provides a limited help capability. For example, if the user enters
# Line 374  Line 388 
388      # Get the parameters.      # Get the parameters.
389      my ($categories, $options, $parmHelp, @argv) = @_;      my ($categories, $options, $parmHelp, @argv) = @_;
390      # Add the tracing options.      # Add the tracing options.
391        if (! exists $options->{trace}) {
392      $options->{trace} = [2, "tracing level"];      $options->{trace} = [2, "tracing level"];
393        }
394      $options->{sql} = [0, "turn on SQL tracing"];      $options->{sql} = [0, "turn on SQL tracing"];
395      $options->{h} = [0, "display command-line options"];      $options->{h} = [0, "display command-line options"];
396      $options->{user} = [$$, "trace log file name suffix"];      $options->{user} = [$$, "trace log file name suffix"];
397        $options->{background} = [0, "spool standard and error output"];
398      # Create a parsing hash from the options hash. The parsing hash      # Create a parsing hash from the options hash. The parsing hash
399      # contains the default values rather than the default value      # contains the default values rather than the default value
400      # and the description. While we're at it, we'll memorize the      # and the description. While we're at it, we'll memorize the
# Line 392  Line 409 
409      }      }
410      # Parse the command line.      # Parse the command line.
411      my ($retOptions, @retParameters) = ParseCommand(\%parseOptions, @argv);      my ($retOptions, @retParameters) = ParseCommand(\%parseOptions, @argv);
412        # Get the logfile suffix.
413        my $suffix = $retOptions->{user};
414        # Check for background mode.
415        if ($retOptions->{background}) {
416            my $outFileName = "$FIG_Config::temp/out$suffix.log";
417            my $errFileName = "$FIG_Config::temp/err$suffix.log";
418            open STDOUT, ">$outFileName";
419            open STDERR, ">$errFileName";
420        }
421      # Now we want to set up tracing. First, we need to know if SQL is to      # Now we want to set up tracing. First, we need to know if SQL is to
422      # be traced.      # be traced.
423      my @cats = @{$categories};      my @cats = @{$categories};
# Line 403  Line 429 
429      # Next, we create the category string by prefixing the trace level      # Next, we create the category string by prefixing the trace level
430      # and joining the categories.      # and joining the categories.
431      my $cats = join(" ", $parseOptions{trace}, @cats);      my $cats = join(" ", $parseOptions{trace}, @cats);
432        # Verify that we can open a file in the temporary directory.
433        my $traceMode = "TEXT";
434        my $traceFileName = "$FIG_Config::temp/trace$suffix.log";
435        if (open TESTTRACE, ">$traceFileName") {
436            $traceMode = "+>$traceFileName";
437            close TESTTRACE;
438        }
439      # Now set up the tracing.      # Now set up the tracing.
440      my $suffix = $retOptions->{user};      TSetup($cats, $traceMode);
     TSetup($cats, "+>$FIG_Config::temp/trace$suffix.log");  
441      # Check for the "h" option. If it is specified, dump the command-line      # Check for the "h" option. If it is specified, dump the command-line
442      # options and exit the program.      # options and exit the program.
443      if ($retOptions->{h}) {      if ($retOptions->{h}) {
# Line 1901  Line 1933 
1933      my ($dirName) = @_;      my ($dirName) = @_;
1934      if (! -d $dirName) {      if (! -d $dirName) {
1935          Trace("Creating $dirName directory.") if T(2);          Trace("Creating $dirName directory.") if T(2);
1936          mkpath $dirName;          eval { mkpath $dirName; };
1937            if ($@) {
1938                Confess("Error creating $dirName: $@");
1939            }
1940        }
1941    }
1942    
1943    =head3 ChDir
1944    
1945    C<< ChDir($dirName); >>
1946    
1947    Change to the specified directory.
1948    
1949    =over 4
1950    
1951    =item dirName
1952    
1953    Name of the directory to which we want to change.
1954    
1955    =back
1956    
1957    =cut
1958    
1959    sub ChDir {
1960        my ($dirName) = @_;
1961        if (! -d $dirName) {
1962            Confess("Cannot change to directory $dirName: no such directory.");
1963        } else {
1964            Trace("Changing to directory $dirName.") if T(4);
1965            my $okFlag = chdir $dirName;
1966            if (! $okFlag) {
1967                Confess("Error switching to directory $dirName.");
1968            }
1969      }      }
1970  }  }
1971    

Legend:
Removed from v.1.39  
changed lines
  Added in v.1.43

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3