[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.41, Wed Mar 15 21:59:29 2006 UTC revision 1.45, Mon May 8 20:37:02 2006 UTC
# Line 19  Line 19 
19    
20      require Exporter;      require Exporter;
21      @ISA = ('Exporter');      @ISA = ('Exporter');
22      @EXPORT = qw(Trace T TSetup QTrace Confess Cluck Min Max Assert Open OpenDir TICK StandardSetup ScriptSetup ScriptFinish Insure);      @EXPORT = qw(Trace T TSetup QTrace Confess Cluck Min Max Assert Open OpenDir TICK StandardSetup ScriptSetup ScriptFinish Insure ChDir);
23      @EXPORT_OK = qw(GetFile GetOptions Merge MergeOptions ParseCommand ParseRecord UnEscape Escape);      @EXPORT_OK = qw(GetFile GetOptions Merge MergeOptions ParseCommand ParseRecord UnEscape Escape);
24      use strict;      use strict;
25      use Carp qw(longmess croak);      use Carp qw(longmess croak);
# 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 330  Line 344 
344          -start    start with this genome          -start    start with this genome
345          -tblFiles output TBL files containing the corrected IDs          -tblFiles output TBL files containing the corrected IDs
346    
347    The caller has the option of modifying the tracing scheme by placing a value
348    for C<trace> in the incoming options hash. The default value can be overridden,
349    or the tracing to the standard output can be turned off by suffixing a minus
350    sign to the trace level. So, for example,
351    
352        { trace => [0, "tracing level (default 0)"],
353           ...
354    
355    would set the default trace level to 0 instead of 2, while
356    
357        { trace => ["2-", "tracing level (default 2)"],
358           ...
359    
360    would leave the default at 2, but trace only to the log file, not to the
361    standard output.
362    
363  The parameters to this method are as follows.  The parameters to this method are as follows.
364    
365  =over 4  =over 4
# Line 347  Line 377 
377  by specifying the options as command-line switches prefixed by a hyphen.  by specifying the options as command-line switches prefixed by a hyphen.
378  Tracing-related options may be added to this hash. If the C<-h> option is  Tracing-related options may be added to this hash. If the C<-h> option is
379  specified on the command line, the option descriptions will be used to  specified on the command line, the option descriptions will be used to
380  explain the options.  explain the options. To turn off tracing to the standard output, add a
381    minus sign to the value for C<trace> (see above).
382    
383  =item parmHelp  =item parmHelp
384    
385  A string that vaguely describes the positional parameters. This is used  A string that vaguely describes the positional parameters. This is used
386  if the user specifies the C<-h> option.  if the user specifies the C<-h> option.
387    
388  =item ARGV  =item argv
389    
390  List of command line parameters, including the option switches, which must  List of command line parameters, including the option switches, which must
391  precede the positional parameters and be prefixed by a hyphen.  precede the positional parameters and be prefixed by a hyphen.
# Line 380  Line 411 
411      $options->{sql} = [0, "turn on SQL tracing"];      $options->{sql} = [0, "turn on SQL tracing"];
412      $options->{h} = [0, "display command-line options"];      $options->{h} = [0, "display command-line options"];
413      $options->{user} = [$$, "trace log file name suffix"];      $options->{user} = [$$, "trace log file name suffix"];
414        $options->{background} = [0, "spool standard and error output"];
415      # Create a parsing hash from the options hash. The parsing hash      # Create a parsing hash from the options hash. The parsing hash
416      # contains the default values rather than the default value      # contains the default values rather than the default value
417      # 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 394  Line 426 
426      }      }
427      # Parse the command line.      # Parse the command line.
428      my ($retOptions, @retParameters) = ParseCommand(\%parseOptions, @argv);      my ($retOptions, @retParameters) = ParseCommand(\%parseOptions, @argv);
429        # Get the logfile suffix.
430        my $suffix = $retOptions->{user};
431        # Check for background mode.
432        if ($retOptions->{background}) {
433            my $outFileName = "$FIG_Config::temp/out$suffix.log";
434            my $errFileName = "$FIG_Config::temp/err$suffix.log";
435            open STDOUT, ">$outFileName";
436            open STDERR, ">$errFileName";
437        }
438      # 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
439      # be traced.      # be traced.
440      my @cats = @{$categories};      my @cats = @{$categories};
# Line 402  Line 443 
443      }      }
444      # Add the default categories.      # Add the default categories.
445      push @cats, "Tracer", "FIG";      push @cats, "Tracer", "FIG";
446      # Next, we create the category string by prefixing the trace level      # Next, we create the category string by joining the categories.
447      # and joining the categories.      my $cats = join(" ", @cats);
448      my $cats = join(" ", $parseOptions{trace}, @cats);      # Check to determine whether or not the caller wants to turn off tracing
449      # Verify that we can open a file in the temporary directory.      # to the standard output.
450      my $traceMode = "TEXT";      my $traceLevel = $retOptions->{trace};
451      my $suffix = $retOptions->{user};      my $textOKFlag = 1;
452        if ($traceLevel =~ /^(.)-/) {
453            $traceLevel = $1;
454            $textOKFlag = 0;
455        }
456        # Now we set up the trace mode.
457        my $traceMode;
458        # Verify that we can open a file in the FIG temporary directory.
459      my $traceFileName = "$FIG_Config::temp/trace$suffix.log";      my $traceFileName = "$FIG_Config::temp/trace$suffix.log";
460      if (open TESTTRACE, ">$traceFileName") {      if (open TESTTRACE, ">$traceFileName") {
461          $traceMode = "+>$traceFileName";          # Here we can trace to a file.
462            $traceMode = ">$traceFileName";
463            if ($textOKFlag) {
464                # Echo to standard output if the text-OK flag is set.
465                $traceMode = "+$traceMode";
466            }
467            # Close the test file.
468          close TESTTRACE;          close TESTTRACE;
469        } else {
470            # Here we can't trace to a file. We trace to the standard output if it's
471            # okay, and the error log otherwise.
472            if ($textOKFlag) {
473                $traceMode = "TEXT";
474            } else {
475                $traceMode = "WARN";
476            }
477      }      }
478      # Now set up the tracing.      # Now set up the tracing.
479      TSetup($cats, $traceMode);      TSetup("$traceLevel $cats", $traceMode);
480      # 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
481      # options and exit the program.      # options and exit the program.
482      if ($retOptions->{h}) {      if ($retOptions->{h}) {
# Line 1910  Line 1972 
1972      my ($dirName) = @_;      my ($dirName) = @_;
1973      if (! -d $dirName) {      if (! -d $dirName) {
1974          Trace("Creating $dirName directory.") if T(2);          Trace("Creating $dirName directory.") if T(2);
1975          mkpath $dirName;          eval { mkpath $dirName; };
1976            if ($@) {
1977                Confess("Error creating $dirName: $@");
1978            }
1979        }
1980    }
1981    
1982    =head3 ChDir
1983    
1984    C<< ChDir($dirName); >>
1985    
1986    Change to the specified directory.
1987    
1988    =over 4
1989    
1990    =item dirName
1991    
1992    Name of the directory to which we want to change.
1993    
1994    =back
1995    
1996    =cut
1997    
1998    sub ChDir {
1999        my ($dirName) = @_;
2000        if (! -d $dirName) {
2001            Confess("Cannot change to directory $dirName: no such directory.");
2002        } else {
2003            Trace("Changing to directory $dirName.") if T(4);
2004            my $okFlag = chdir $dirName;
2005            if (! $okFlag) {
2006                Confess("Error switching to directory $dirName.");
2007            }
2008      }      }
2009  }  }
2010    

Legend:
Removed from v.1.41  
changed lines
  Added in v.1.45

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3