#!/usr/bin/perl -w
=head1 Set Primary Group
This script takes as parameters an NMPDR group name and a list of genome IDs and
updates the Sprout database to put the genomes into that group.
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 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 and
CIC, 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.
=back
=cut
use strict;
use Tracer;
use Cwd;
use File::Copy;
use File::Path;
use FIG;
use Sprout;
use SFXlate;
# Get the command-line options and parameters.
my ($options, @parameters) = StandardSetup([qw(Sprout) ],
{
phone => ["", "phone number (international format) to call when load finishes"],
},
" ... ",
@ARGV);
# Set a variable to contain return type information.
my $rtype;
# Insure we catch errors.
eval {
# Get the sprout database.
my $sprout = SFXlate->new_sprout_only();
# Save the group name.
my $groupName = shift @parameters;
# Loop through the genomes, doing the update.
for my $genome (@parameters) {
Trace("Converting $genome to $groupName.") if T(3);
$sprout->UpdateEntity('Genome', $genome, { 'primary-group' => $groupName });
}
Trace("Processing 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}, "Set Primary Group 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;