[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.35, Wed Jan 11 19:26:45 2006 UTC revision 1.36, Sun Jan 15 21:27:33 2006 UTC
# Line 27  Line 27 
27      use FIG_Config;      use FIG_Config;
28      use PageBuilder;      use PageBuilder;
29      use Digest::MD5;      use Digest::MD5;
30        use File::Basename;
31    
32  =head1 Tracing and Debugging Helpers  =head1 Tracing and Debugging Helpers
33    
# Line 208  Line 209 
209    
210  =head3 StandardSetup  =head3 StandardSetup
211    
212  C<< my ($options, @parameters) = StandardSetup(\@categories, \%options, @ARGV); >>  C<< my ($options, @parameters) = StandardSetup(\@categories, \%options, $parmHelp, @ARGV); >>
213    
214  This method performs standard command-line parsing and tracing setup. The return  This method performs standard command-line parsing and tracing setup. The return
215  values are a hash of the command-line options and a list of the positional  values are a hash of the command-line options and a list of the positional
# Line 261  Line 262 
262  For a genome-by-genome update, use 3.  For a genome-by-genome update, use 3.
263    
264  The I<options> parameter is a reference to a hash containing the command-line  The I<options> parameter is a reference to a hash containing the command-line
265  options and their default values. Command-line options may be in the form of switches  options, their default values, and an explanation of what they mean. Command-line
266  or keywords. In the case of a switch, the option value is 1 if it is specified and  options may be in the form of switches or keywords. In the case of a switch, the
267  0 if it is not specified. In the case of a keyword, the value is separated from the  option value is 1 if it is specified and 0 if it is not specified. In the case
268  option name by an equal sign. You can see this last in the command-line example above.  of a keyword, the value is separated from the option name by an equal sign. You
269    can see this last in the command-line example above.
270    
271  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
272  C<TransactFeatures>. It accepts a list of positional parameters plus the options  C<TransactFeatures>. It accepts a list of positional parameters plus the options
# Line 272  Line 274 
274  the following code.  the following code.
275    
276      my ($options, @parameters) = Tracer::StandardSetup(["DocUtils"],      my ($options, @parameters) = Tracer::StandardSetup(["DocUtils"],
277                                                        { safe => 0, noAlias => 0,                          { safe => [0, "use database transactions"],
278                                                          start => ' ', tblFiles => 0},                            noAlias => [0, "do not expect aliases in CHANGE transactions"],
279                              start => [' ', "start with this genome"],
280                              tblFiles => [0, "output TBL files containing the corrected IDs"] },
281                            "command transactionDirectory IDfile",
282                                                      @ARGV);                                                      @ARGV);
283    
284    
# Line 302  Line 307 
307  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
308  upsetting the command-line utilities.  upsetting the command-line utilities.
309    
310    Finally, if the special option C<-h> is specified, the option names will
311    be traced at level 0 and the program will exit without processing.
312    This provides a limited help capability. For example, if the user enters
313    
314        TransactFeatures -h
315    
316    he would see the following output.
317    
318        TransactFeatures [options] command transactionDirectory IDfile
319            -trace    tracing level (default 2)
320            -sql      trace SQL commands
321            -safe     use database transactions
322            -noAlias  do not expect aliases in CHANGE transactions
323            -start    start with this genome
324            -tblFiles output TBL files containing the corrected IDs
325    
326  The parameters to this method are as follows.  The parameters to this method are as follows.
327    
328  =over 4  =over 4
# Line 315  Line 336 
336  =item options  =item options
337    
338  Reference to a hash containing the legal options for the current command mapped  Reference to a hash containing the legal options for the current command mapped
339  to their default values. The use can override the defaults by specifying the  to their default values and descriptions. The user can override the defaults
340  options as command-line switches prefixed by a hyphen. Tracing-related options  by specifying the options as command-line switches prefixed by a hyphen.
341  may be added to this hash.  Tracing-related options may be added to this hash. If the C<-h> option is
342    specified on the command line, the option descriptions will be used to
343    explain the options.
344    
345    =item parmHelp
346    
347    A string that vaguely describes the positional parameters. This is used
348    if the user specifies the C<-h> option.
349    
350  =item ARGV  =item ARGV
351    
# Line 337  Line 365 
365    
366  sub StandardSetup {  sub StandardSetup {
367      # Get the parameters.      # Get the parameters.
368      my ($categories, $options, @argv) = @_;      my ($categories, $options, $parmHelp, @argv) = @_;
369      # Add the tracing options.      # Add the tracing options.
370      $options->{trace} = 2;      $options->{trace} = [2, "tracing level"];
371      $options->{sql} = 0;      $options->{sql} = [0, "turn on SQL tracing"];
372        $options->{h} = [0, "display command-line options"];
373        # Create a parsing hash from the options hash. The parsing hash
374        # contains the default values rather than the default value
375        # and the description. While we're at it, we'll memorize the
376        # length of the longest option name.
377        my $longestName = 0;
378        my %parseOptions = ();
379        for my $key (keys %{$options}) {
380            if (length $key > $longestName) {
381                $longestName = length $key;
382            }
383            $parseOptions{$key} = $options->{$key}->[0];
384        }
385      # Parse the command line.      # Parse the command line.
386      my ($retOptions, @retParameters) = ParseCommand($options, @argv);      my ($retOptions, @retParameters) = ParseCommand(\%parseOptions, @argv);
387      # 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
388      # be traced.      # be traced.
389      my @cats = @{$categories};      my @cats = @{$categories};
# Line 353  Line 394 
394      push @cats, "Tracer", "FIG";      push @cats, "Tracer", "FIG";
395      # Next, we create the category string by prefixing the trace level      # Next, we create the category string by prefixing the trace level
396      # and joining the categories.      # and joining the categories.
397      my $cats = join(" ", $options->{trace}, @cats);      my $cats = join(" ", $parseOptions{trace}, @cats);
398      # Now set up the tracing.      # Now set up the tracing.
399      TSetup($cats, "+>$FIG_Config::temp/trace.log");      TSetup($cats, "+>$FIG_Config::temp/trace.log");
400        # Check for the "h" option. If it is specified, dump the command-line
401        # options and exit the program.
402        if ($retOptions->{h}) {
403            $0 =~ m#[/\\](\w+)(\.pl)?$#i;
404            Trace("$1 [options] $parmHelp") if T(0);
405            for my $key (sort keys %{$options}) {
406                my $name = Pad($key, $longestName, 0, ' ');
407                my $desc = $options->{$key}->[1];
408                if ($options->{$key}->[0]) {
409                    $desc .= " (default " . $options->{$key}->[0] . ")";
410                }
411                Trace("  $name $desc") if T(0);
412            }
413            exit(0);
414        }
415      # Return the parsed parameters.      # Return the parsed parameters.
416      return ($retOptions, @retParameters);      return ($retOptions, @retParameters);
417  }  }
# Line 915  Line 971 
971          # Convert it to lower case before we hash it.          # Convert it to lower case before we hash it.
972          $category = lc $category;          $category = lc $category;
973          # Use the category and tracelevel to compute the result.          # Use the category and tracelevel to compute the result.
974            if (ref $traceLevel) {
975                Confess("Bad trace level.");
976            } elsif (ref $TraceLevel) {
977                Confess("Bad trace config.");
978            }
979          $retVal = ($traceLevel <= $TraceLevel && ($AllTrace || exists $Categories{$category}));          $retVal = ($traceLevel <= $TraceLevel && ($AllTrace || exists $Categories{$category}));
980      }      }
981      # Return the computed result.      # Return the computed result.

Legend:
Removed from v.1.35  
changed lines
  Added in v.1.36

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3