my ($self) = @_;
my $o = $self->opts();
#Processing -opt 1 -opt 2,3 into opt => [1,2,3]
$self->_cmd_line_to_array('databases') if $o->{databases};
$self->_cmd_line_to_array('groups') if $o->{groups};
$self->_cmd_line_to_array('species') if $o->{species};
my $original_databases_args = $o->{databases};
#Tables
$self->_cmd_line_to_array('tables');
$self->v(q{Will work with the
tables [%s]}, join(q{,}, @{ $o->{
tables} }));
}
$self->_set_opts_from_hostname();
} else {
$o->{port} = 3306 if !$o->{port};
if ($o->{pattern}) {
my $p = $o->{pattern};
$p = qr/$p/;
$o->{databases} = $self->_all_dbs($p);
}
$o->{directory} = File::Spec->rel2abs($o->{directory});
}
if(! $o->{username}) {
pod2usage(
-msg => 'No -username given on the command line or in the configuration file',
-exitval => 1,
-verbose => 0
);
}
$self->v(q{Using the database server %s@%s:%d},
map { $o->{$_} } qw/username host port/);
#Filter for those on the specified server; sometimes redundant
my %dbs =
map { $_ => 1 } @{ $self->_all_dbs() };
my @final_dbs;
foreach my $db (@{$o->{databases}}) {
if($dbs{$db}) {
push(@final_dbs, $db);
}
else {
$self->v('DB %s is not available from the specified server', $db);
}
}
$o->{databases} = \@final_dbs;
#Filtering DBs based on groups & species
if ($o->{groups}) {
my %dbs;
foreach my $group (@{ $o->{groups} }) {
$self->v('Filtering for group %s', $group);
%dbs =
map { $_ => 1 } grep { / _ $group _ /xms } @{ $o->{databases} };
}
$o->{databases} = [ keys %dbs ];
}
if ($o->{species}) {
my %dbs;
foreach my $species (@{ $o->{species} }) {
$self->v('Filtering for species %s', $species);
%dbs =
map { $_ => 1 } grep { / $species _ /xms } @{ $o->{databases} };
}
$o->{databases} = [ keys %dbs ];
}
#Do we have any DBs left to process?
my $db_count = scalar(@{ $o->{databases} });
if ($db_count == 0) {
my $msg = 'No databases found on the server ' . $o->{host};
if($original_databases_args && $o->{
defaults}) {
my $version = $o->{version} || '-NONE';
$msg .= qq{. You specified the -database arg and -
defaults. Are you on the correct server or did -version
'$version' excluded
this DB?};
}
pod2usage(-msg => $msg, -exitval => 1, -verbose => 0);
}
$self->v(q{Working %d database(s)}, $db_count);
$o->{databases} = [ sort { $a cmp $b } @{ $o->{databases} } ];
$o->{verbose} = 1
if $o->{
dry};
return;
}