Code clean up.

git-svn-id: svn://192.168.202.10@1149 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mikec
2009-06-09 20:53:22 +00:00
parent 1ef2c83199
commit d422769095
+79 -79
View File
@@ -12,17 +12,17 @@ use DBI;
# function to print out the help for this script
sub print_help {
print "$0 - updates the url in the recording_log\n";
print "command-line options:\n";
print " [--debug] = shows the sql as it is being executed.\n";
print " [--test] = activates debuging and does not actually\n";
print " execute the updates.\n";
print " [--old-server-url] = the old url used to access the recordings.\n";
print " This is a required argument.\n";
print " [--new-server-url] = the new url used to access the recordings.\n";
print " This is a required argument.\n\n";
print "$0 - updates the url in the recording_log\n";
print "command-line options:\n";
print " [--debug] = shows the sql as it is being executed.\n";
print " [--test] = activates debuging and does not actually\n";
print " execute the updates.\n";
print " [--old-server-url] = the old url used to access the recordings.\n";
print " This is a required argument.\n";
print " [--new-server-url] = the new url used to access the recordings.\n";
print " This is a required argument.\n\n";
exit;
exit;
}
# default path to astguiclient configuration file:
@@ -34,21 +34,21 @@ open(CONFIG, "$PATHconf") || die "can't open $PATHconf: $!\n";
close(CONFIG);
$i=0;
foreach(@config) {
$line = $config[$i];
$line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi;
if ($line =~ /^VARserver_ip/)
{$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;}
if ($line =~ /^VARDB_server/)
{$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;}
if ($line =~ /^VARDB_database/)
{$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;}
if ($line =~ /^VARDB_user/)
{$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;}
if ($line =~ /^VARDB_pass/)
{$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;}
if ($line =~ /^VARDB_port/)
{$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;}
$i++;
$line = $config[$i];
$line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi;
if ($line =~ /^VARserver_ip/)
{$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;}
if ($line =~ /^VARDB_server/)
{$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;}
if ($line =~ /^VARDB_database/)
{$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;}
if ($line =~ /^VARDB_user/)
{$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;}
if ($line =~ /^VARDB_pass/)
{$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;}
if ($line =~ /^VARDB_port/)
{$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;}
$i++;
}
# initialize the variables
@@ -59,58 +59,58 @@ $TEST = 0;
# begin parsing run-time options
if ( length($ARGV[0]) > 1 ) {
$i=0;
while ($#ARGV >= $i) {
$args = "$args $ARGV[$i]";
$i++;
}
$i=0;
while ($#ARGV >= $i) {
$args = "$args $ARGV[$i]";
$i++;
}
if ($args =~ /--help/i) {
&print_help;
} else {
# activate debugging
if ($args =~ /--debug/i) {
$DB=1;
}
if ($args =~ /--help/i) {
&print_help;
} else {
# activate debugging
if ($args =~ /--debug/i) {
$DB=1;
}
# activate test mode
if ($args =~ /--test/i) {
$DB=1;
$TEST=1;
}
# activate test mode
if ($args =~ /--test/i) {
$DB=1;
$TEST=1;
}
# get the old server url
if ($args =~ /--old-server-url=/i) {
@CLIoldurlARY = split(/--old-server-url=/,$args);
@CLIoldurlARX = split(/ /,$CLIoldurlARY[1]);
$old_url = $CLIoldurlARX[0];
}
# get the old server url
if ($args =~ /--old-server-url=/i) {
@CLIoldurlARY = split(/--old-server-url=/,$args);
@CLIoldurlARX = split(/ /,$CLIoldurlARY[1]);
$old_url = $CLIoldurlARX[0];
}
# get the new server url
if ($args =~ /--new-server-url=/i) {
@CLInewurlARY = split(/--new-server-url=/,$args);
@CLInewurlARX = split(/ /,$CLInewurlARY[1]);
$new_url = $CLInewurlARX[0];
}
}
# get the new server url
if ($args =~ /--new-server-url=/i) {
@CLInewurlARY = split(/--new-server-url=/,$args);
@CLInewurlARX = split(/ /,$CLInewurlARY[1]);
$new_url = $CLInewurlARX[0];
}
}
} else {
# we didnt get any arguments
&print_help;
# we didnt get any arguments
&print_help;
}
# make sure they set something
if (( $new_url eq "") || ( $old_url eq "")) {
&print_help;
&print_help;
}
# connect to the db
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
or die "Couldn't connect to database: " . DBI->errstr;
# get all the recordings with the old_url
$stmtA = "SELECT recording_id, location from recording_log where location LIKE '$old_url%';";
if ( $DB ) {
print $stmtA . "\n";
print $stmtA . "\n";
}
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
@@ -119,29 +119,29 @@ $rec_count=0;
# cycle through them
while ($sthArows > $rec_count) {
@aryA = $sthA->fetchrow_array;
@aryA = $sthA->fetchrow_array;
# get the parameters from the DB
$rec_id = "$aryA[0]";
$location = "$aryA[1]";
# get the parameters from the DB
$rec_id = "$aryA[0]";
$location = "$aryA[1]";
# change the url
$new_loc = $location;
$new_loc =~ s/$old_url/$new_url/gi;
# change the url
$new_loc = $location;
$new_loc =~ s/$old_url/$new_url/gi;
# UPDATE THE recording_log RECORD
$stmtB = "UPDATE recording_log SET location='$new_loc' where recording_id='$rec_id';";
if ( $DB ) {
print $stmtB . "\n";
}
# UPDATE THE recording_log RECORD
$stmtB = "UPDATE recording_log SET location='$new_loc' where recording_id='$rec_id';";
if ( $DB ) {
print $stmtB . "\n";
}
# execute the update if we are not in test mode
if ( $TEST == 0 ) {
$sthB = $dbhA->prepare($stmtB) or die "preparing: ",$dbhB->errstr;
$sthB->execute or die "executing: $stmtB ", $dbhB->errstr;
$sthB->finish();
}
$rec_count++;
# execute the update if we are not in test mode
if ( $TEST == 0 ) {
$sthB = $dbhA->prepare($stmtB) or die "preparing: ",$dbhB->errstr;
$sthB->execute or die "executing: $stmtB ", $dbhB->errstr;
$sthB->finish();
}
$rec_count++;
}
print "Updated $rec_count records in the recording_log table\n";