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

Annotation of /Sprout/ERDBReloader.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 :     #
4 :     # Copyright (c) 2003-2006 University of Chicago and Fellowship
5 :     # for Interpretations of Genomes. All Rights Reserved.
6 :     #
7 :     # This file is part of the SEED Toolkit.
8 :     #
9 :     # The SEED Toolkit is free software. You can redistribute
10 :     # it and/or modify it under the terms of the SEED Toolkit
11 :     # Public License.
12 :     #
13 :     # You should have received a copy of the SEED Toolkit Public License
14 :     # along with this program; if not write to the University of Chicago
15 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
16 :     # Genomes at veronika@thefig.info or download a copy from
17 :     # http://www.theseed.org/LICENSE.TXT.
18 :     #
19 :    
20 :     use strict;
21 :     use Tracer;
22 :     use ERDB;
23 :     use ERDBLoadGroup;
24 :     use ERDBGenerate;
25 :     use ERDBExtras;
26 :     use Stats;
27 :     use Time::HiRes;
28 :    
29 :    
30 :     =head1 ERDBReloader Script
31 :    
32 :     ERDBReloader [options] <database> <table1> <table2> ...
33 :    
34 :     ERDB Database Load Finisher
35 :    
36 :     =head2 Introduction
37 :    
38 :     This script loads a one or more individual tables from their load files in
39 :     the load directory.
40 :    
41 :     Unlike L<ERDBGenerator.pl> and L<ERDBLoader.pl>, which operate on table
42 :     groups, this script operates on individual tables. The theory is that you
43 :     use this method to do simple repair operations instead of massive reloads.
44 :    
45 :     =head2 Positional Parameters
46 :    
47 :     =over 4
48 :    
49 :     =item database
50 :    
51 :     Name of the ERDB database. This should be the class name for the subclass used
52 :     to access the database.
53 :    
54 :     =back
55 :    
56 :     =head2 Command-Line Options
57 :    
58 :     =over 4
59 :    
60 :     =item trace
61 :    
62 :     Specifies the tracing level. The higher the tracing level, the more messages
63 :     will appear in the trace log. Use E to specify emergency tracing.
64 :    
65 :     =item user
66 :    
67 :     Name suffix to be used for log files. If omitted, the PID is used.
68 :    
69 :     =item sql
70 :    
71 :     If specified, turns on tracing of SQL activity.
72 :    
73 :     =item background
74 :    
75 :     Save the standard and error output to files. The files will be created
76 :     in the FIG temporary directory and will be named C<err>I<User>C<.log> and
77 :     C<out>I<User>C<.log>, respectively, where I<User> is the value of the
78 :     B<user> option above.
79 :    
80 :     =item help
81 :    
82 :     Display this command's parameters and options.
83 :    
84 :     =item warn
85 :    
86 :     Create an event in the RSS feed when an error occurs.
87 :    
88 :     =item phone
89 :    
90 :     Phone number to message when the script is complete.
91 :    
92 :     =item loadDirectory
93 :    
94 :     Directory containing the load files. This option allows you to request that
95 :     load files from another version of the NMPDR be used, which is useful when
96 :     creating a new NMPDR: we can yank in the data from the previous database while
97 :     waiting for the new load files to be generated.
98 :    
99 :     =item dbName
100 :    
101 :     SQL name of the target database. If not specified, the default name is used.
102 :     This option allows you to specify a backup or alternate database that can
103 :     be loaded without compromising the main database.
104 :    
105 :     =back
106 :    
107 :     =cut
108 :    
109 :     # Get the command-line options and parameters.
110 :     my ($options, @parameters) = StandardSetup([qw(ERDB Stats) ],
111 :     {
112 :     dbName => ["", "if specified, the SQL name of the target database"],
113 :     trace => ["2", "tracing level"],
114 :     phone => ["", "phone number (international format) to call when load finishes"],
115 :     loadDirectory => ["", "if specified, an alternate directory containing the load files"],
116 :     },
117 :     "<database> <table1> <table2> ...",
118 :     @ARGV);
119 :     # Set a variable to contain return type information.
120 :     my $rtype;
121 :     # Insure we catch errors.
122 :     eval {
123 :     # Get the parameters.
124 :     my ($database, @tables) = @parameters;
125 :     # Connect to the database and get its load directory.
126 :     my $erdb = ERDB::GetDatabase($database, undef, %$options);
127 :     # Get the load directory for this database.
128 :     my $directory = $options->{loadDirectory} || $erdb->LoadDirectory();
129 :     # Create a statistics object to track our progress.
130 :     my $stats = Stats->new();
131 :     # Start a timer.
132 :     my $totalStart = time();
133 :     # Loop through the tables.
134 :     for my $table (@tables) {
135 :     # Compute the load file name.
136 :     my $fileName = ERDBGenerate::CreateFileName($table, undef, 'data', $directory);
137 :     # Do the actual load.
138 :     my $newStats = $erdb->LoadTable($fileName, $table, truncate => 1, failOnError => 1);
139 :     $stats->Accumulate($newStats);
140 :     Trace("$fileName loaded into $table.") if T(3);
141 :     }
142 :     # Compute the total time.
143 :     $stats->Add('total-time' => (time() - $totalStart));
144 :     # Display the statistics from this run.
145 :     Trace("Statistics for reload:\n" . $stats->Show()) if T(2);
146 :     };
147 :     if ($@) {
148 :     Trace("Script failed with error: $@") if T(0);
149 :     } else {
150 :     Trace("Script complete.") if T(2);
151 :     }
152 :     if ($options->{phone}) {
153 :     my $msgID = Tracer::SendSMS($options->{phone}, "ERDBReloader completed.");
154 :     if ($msgID) {
155 :     Trace("Phone message sent with ID $msgID.") if T(2);
156 :     } else {
157 :     Trace("Phone message not sent.") if T(2);
158 :     }
159 :     }
160 :    
161 :    
162 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3