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

Annotation of /Sprout/DBConvert.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 DBConvert
4 :    
5 :     This script converts an ERDB database definition to a PPO database definition.
6 :     An options is provided to also generate the PPO files from the generated XML.
7 :    
8 :     Two positional parameters are required. The first is the name of the ERDB
9 :     XML file and the second is the directory in which to deploy the PPO database.
10 :    
11 :     For example, the following command
12 :    
13 :     DBConvert -ppogen=ppo_v19_Sprout SproutDBD.xml SproutPPO
14 :    
15 :     will convert SproutDBD.xml to an XML file called SproutPPO.xml in the same
16 :     directory, and will deploy the database in the directory SproutPPO. The
17 :     database name will be C<ppo_v19_Sprout>.
18 :    
19 :     The currently-supported command-line options are as follows.
20 :    
21 :     =over 4
22 :    
23 :     =item user
24 :    
25 :     Name suffix to be used for log files. If omitted, the PID is used.
26 :    
27 :     =item trace
28 :    
29 :     Numeric trace level. A higher trace level causes more messages to appear. The
30 :     default trace level is 2. Tracing will be directly to the standard output
31 :     as well as to a C<trace>I<User>C<.log> file in the FIG temporary directory,
32 :     where I<User> is the value of the B<user> option above.
33 :    
34 :     =item sql
35 :    
36 :     If specified, turns on tracing of SQL activity.
37 :    
38 :     =item background
39 :    
40 :     Save the standard and error output to files. The files will be created
41 :     in the FIG temporary directory and will be named C<err>I<User>C<.log> and
42 :     C<out>I<User>C<.log>, respectively, where I<User> is the value of the
43 :     B<user> option above.
44 :    
45 :     =item h
46 :    
47 :     Display this command's parameters and options.
48 :    
49 :     =item phone
50 :    
51 :     Phone number to message when the script is complete.
52 :    
53 :     =item ppogen
54 :    
55 :     If specified, the PPO database files will be generated from the generated XML. The
56 :     value of the parameter is the target database name.
57 :    
58 :     =back
59 :    
60 :     =cut
61 :    
62 :     use strict;
63 :     use Tracer;
64 :     use DocUtils;
65 :     use TestUtils;
66 :     use Cwd;
67 :     use File::Copy;
68 :     use File::Path;
69 :     use FIG;
70 :     use ERDB;
71 : parrello 1.2 use PPOGenerator;
72 : parrello 1.1
73 :     # Get the command-line options and parameters.
74 :     my ($options, @parameters) = StandardSetup([qw(ERDB) ],
75 :     {
76 :     trace => ["2", "trace level"],
77 :     phone => ["", "phone number (international format) to call when load finishes"],
78 :     ppogen => ["", "name of the target PPO database; if specified, the PPO database will be deployed"]
79 :     },
80 :     "<dbdFile> <targetDirectory>",
81 :     @ARGV);
82 :     # Set a variable to contain return type information.
83 :     my $rtype;
84 :     # Insure we catch errors.
85 :     eval {
86 :     my ($dbdFile, $targetDirectory) = @parameters;
87 :     # Insure we can find the input file.
88 :     if (! -f $dbdFile) {
89 :     Confess("Input XML file $dbdFile not found.");
90 :     }
91 :     # Insure the target directory exists.
92 :     if (! -d $targetDirectory) {
93 :     Trace("Creating target directory $targetDirectory.") if T(2);
94 :     mkdir $targetDirectory;
95 :     }
96 :     # Compute the location for the PPO XML file. It's placed right next to the target directory.
97 :     my $targetXmlFile = "$targetDirectory.xml";
98 :     # Call ERDB to convert the database.
99 :     ERDB::CreatePPO($dbdFile, $targetXmlFile);
100 :     # Check to see if we should deploy the database.
101 :     if ($options->{ppogen}) {
102 :     # We're deploying, so do it.
103 :     Trace("Deploying PPO database as $options->{ppogen}.") if T(2);
104 : parrello 1.2 PPOGenerator->deploy($targetXmlFile, $targetDirectory, $options->{ppogen});
105 : parrello 1.1 }
106 :     Trace("Conversion complete.") if T(2);
107 :     };
108 :     if ($@) {
109 :     Trace("Script failed with error: $@") if T(0);
110 :     $rtype = "error";
111 :     } else {
112 :     Trace("Script complete.") if T(2);
113 :     $rtype = "no error";
114 :     }
115 :     if ($options->{phone}) {
116 :     my $msgID = Tracer::SendSMS($options->{phone}, "DBConvert terminated with $rtype.");
117 :     if ($msgID) {
118 :     Trace("Phone message sent with ID $msgID.") if T(2);
119 :     } else {
120 :     Trace("Phone message not sent.") if T(2);
121 :     }
122 :     }
123 :    
124 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3