#!/usr/bin/perl -w =head1 DBConvert This script converts an ERDB database definition to a PPO database definition. An options is provided to also generate the PPO files from the generated XML. Two positional parameters are required. The first is the name of the ERDB XML file and the second is the directory in which to deploy the PPO database. For example, the following command DBConvert -ppogen=ppo_v19_Sprout SproutDBD.xml SproutPPO will convert SproutDBD.xml to an XML file called SproutPPO.xml in the same directory, and will deploy the database in the directory SproutPPO. The database name will be C. The currently-supported command-line options are as follows. =over 4 =item user Name suffix to be used for log files. If omitted, the PID is used. =item trace Numeric trace level. A higher trace level causes more messages to appear. The default trace level is 2. Tracing will be directly to the standard output as well as to a CIC<.log> file in the FIG temporary directory, where I is the value of the B option above. =item sql If specified, turns on tracing of SQL activity. =item background Save the standard and error output to files. The files will be created in the FIG temporary directory and will be named CIC<.log> and CIC<.log>, respectively, where I is the value of the B option above. =item h Display this command's parameters and options. =item phone Phone number to message when the script is complete. =item ppogen If specified, the PPO database files will be generated from the generated XML. The value of the parameter is the target database name. =back =cut use strict; use Tracer; use Cwd; use File::Copy; use File::Path; use FIG; use ERDB; use PPOGenerator; # Get the command-line options and parameters. my ($options, @parameters) = StandardSetup([qw(ERDB) ], { trace => ["2", "trace level"], phone => ["", "phone number (international format) to call when load finishes"], ppogen => ["", "name of the target PPO database; if specified, the PPO database will be deployed"] }, " ", @ARGV); # Set a variable to contain return type information. my $rtype; # Insure we catch errors. eval { my ($dbdFile, $targetDirectory) = @parameters; # Insure we can find the input file. if (! -f $dbdFile) { Confess("Input XML file $dbdFile not found."); } # Insure the target directory exists. if (! -d $targetDirectory) { Trace("Creating target directory $targetDirectory.") if T(2); mkdir $targetDirectory; } # Compute the location for the PPO XML file. It's placed right next to the target directory. my $targetXmlFile = "$targetDirectory.xml"; # Call ERDB to convert the database. ERDB::CreatePPO($dbdFile, $targetXmlFile); # Check to see if we should deploy the database. if ($options->{ppogen}) { # We're deploying, so do it. Trace("Deploying PPO database as $options->{ppogen}.") if T(2); PPOGenerator->deploy($targetXmlFile, $targetDirectory, $options->{ppogen}); } Trace("Conversion complete.") if T(2); }; if ($@) { Trace("Script failed with error: $@") if T(0); $rtype = "error"; } else { Trace("Script complete.") if T(2); $rtype = "no error"; } if ($options->{phone}) { my $msgID = Tracer::SendSMS($options->{phone}, "DBConvert terminated with $rtype."); if ($msgID) { Trace("Phone message sent with ID $msgID.") if T(2); } else { Trace("Phone message not sent.") if T(2); } } 1;