[Bio] / Sprout / LoadScript.pl Repository:
ViewVC logotype

Annotation of /Sprout/LoadScript.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (view) (download) (as text)

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 :     =head1 General-Purpose Load Script
4 :    
5 :     This method executes a list of commands. If a command fails, it writes
6 :     the unprocessed commands into a file so they can be resumed.
7 :    
8 : parrello 1.2 The command takes multiple positional parameters. The first
9 : parrello 1.1 parameter must be one of the following.
10 :    
11 :     =over 4
12 :    
13 :     =item test
14 :    
15 :     Executes a series of simple test commands to verify the operation
16 :     of this script.
17 :    
18 :     =item seed
19 :    
20 :     Loads the SEED database.
21 :    
22 :     =back
23 :    
24 : parrello 1.2 The remaining positional parameters are added to the list of trace modules. So,
25 :     for example, the following command
26 :    
27 :     LoadScript seed FIG Stats
28 :    
29 :     would run the SEED load
30 :     addition to the positional parameters, the following command-line options are
31 :     supported.
32 : parrello 1.1
33 :     =over 4
34 :    
35 :     =item trace
36 :    
37 :     Numeric trace level. A higher trace level causes more messages to appear. The
38 : parrello 1.2 default trace level is C<2>.
39 : parrello 1.1
40 :     =item skip
41 :    
42 :     Number of commands to skip. This allows the user to resume an interrupted load.
43 : parrello 1.2 The default is C<0>, indicating that the whole list will be executed.
44 :    
45 :     =item list
46 :    
47 :     TRUE if the commands should simply be listed, else FALSE. The default is FALSE (C<0>).
48 : parrello 1.1
49 :     =back
50 :    
51 :     =cut
52 :    
53 :     use strict;
54 :     use Tracer;
55 :     use FIG;
56 :     use Sprout;
57 :     use DocUtils;
58 :     use TestUtils;
59 :     use Cwd;
60 :     use File::Copy;
61 :     use File::Path;
62 :    
63 :     # Get the command-line options.
64 : parrello 1.2 my ($options, @parameters) = Tracer::ParseCommand({ trace => 2, skip => 0, list => 0 }, @ARGV);
65 :     # Get the command and convert it to lower case.
66 :     my $command = lc shift @parameters;
67 : parrello 1.1 # Set up tracing.
68 :     my $traceLevel = $options->{trace};
69 : parrello 1.2 my $traceString = join(" ", $traceLevel, "errors", "Tracer", "COMMANDS", @parameters);
70 :     TSetup("$traceString", "+>$FIG_Config::temp/trace.log");
71 :     # Insure the other FIG applications use the same trace setting.
72 :     $ENV{Trace} = $traceString;
73 :     $ENV{TraceType} = "+>>$FIG_Config::temp/trace.log";
74 : parrello 1.1 # Create the command list.
75 :     my @commandList;
76 :     if ($command eq 'seed') {
77 : parrello 1.2 # Get the list of commands for doing a full load.
78 : parrello 1.1 @commandList = FIG::load_all_list();
79 : parrello 1.2 # Add the command to initialize the database.
80 :     unshift @commandList, "init_FIG";
81 : parrello 1.1 } elsif ($command eq 'test') {
82 :     for (my $i = 1; $i < 10; $i++) {
83 :     push @commandList, "TestScript line$i";
84 :     }
85 :     } else {
86 :     Confess("Invalid command $command.");
87 :     }
88 : parrello 1.2 # Set up the trace.
89 :     my $action = ($options->{list} ? "Showing" : "Running");
90 : parrello 1.1 # Execute the commands.
91 : parrello 1.2 my $n = @commandList;
92 :     for (my $i = $options->{skip}; $i < $n; $i++) {
93 : parrello 1.1 my $command = $commandList[$i];
94 : parrello 1.2 my $counter = $i + 1;
95 :     Trace(">> $action ($counter) of $n: $command.") if T(COMMANDS => 0);
96 :     if (! $options->{list}) {
97 :     system($command);
98 :     }
99 : parrello 1.1 }
100 :     Trace("Load complete") if T(0);
101 :    
102 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3