view release on metacpan or search on metacpan
lib/App/ClusterSSH/Base.pm view on Meta::CPAN
sub set_lang {
my ( $self, $lang ) = @_;
$self->debug( 6, $self->loc( 'Setting language to "[_1]"', $lang ), );
return $self;
}
sub set_debug_level {
my ( $self, $level ) = @_;
if ( !defined $level ) {
croak(
App::ClusterSSH::Exception->throw(
error => _translate('Debug level not provided')
)
);
}
if ( $level > 9 ) {
$level = 9;
}
$debug_level = $level;
return $self;
}
lib/App/ClusterSSH/Base.pm view on Meta::CPAN
my ($self) = @_;
exit;
}
sub config {
my ($self) = @_;
if ( !$app_configuration ) {
croak(
App::ClusterSSH::Exception->throw(
_translate('config has not yet been set')
)
);
}
return $app_configuration;
}
sub set_config {
my ( $self, $config ) = @_;
if ($app_configuration) {
croak(
App::ClusterSSH::Exception->throw(
_translate('config has already been set')
)
);
}
if ( !$config ) {
croak(
App::ClusterSSH::Exception->throw(
_translate('passed config is empty')
)
);
}
$self->debug( 3, _translate('Setting app configuration') );
$app_configuration = $config;
return $self;
}
sub load_file {
my ( $self, %args ) = @_;
if ( !$args{filename} ) {
croak(
App::ClusterSSH::Exception->throw(
error => '"filename" arg not passed'
)
);
}
if ( !$args{type} ) {
croak(
App::ClusterSSH::Exception->throw(
error => '"type" arg not passed'
)
);
}
$self->debug( 2, 'Loading in config file: ', $args{filename} );
if ( !-e $args{filename} ) {
croak(
App::ClusterSSH::Exception::LoadFile->throw(
error => $self->loc(
'Unable to read file [_1]: [_2]' . $/, $args{filename},
$!
),
),
);
}
my $regexp
= $args{type} eq 'config' ? qr/\s*(\S+)\s*=\s*(.*)/
: $args{type} eq 'cluster' ? qr/\s*(\S+)\s+(.*)/
: croak(
App::ClusterSSH::Exception::LoadFile->throw(
error => 'Unknown arg type: ',
$args{type}
)
);
open( my $fh, '<', $args{filename} )
or croak(
App::ClusterSSH::Exception::LoadFile->throw(
error => $self->loc(
"Unable to read file [_1]: [_2]",
$args{filename}, $!
)
),
);
my %results;
my $line;
lib/App/ClusterSSH/Base.pm view on Meta::CPAN
else {
$results{$key} = $value;
}
$self->debug( 3, "$key=$value" );
$self->debug( 7, "entry now reads: $key=$results{$key}" );
}
}
close($fh)
or croak(
App::ClusterSSH::Exception::LoadFile->throw(
error => "Could not close $args{filename} after reading: $!"
),
);
return %results;
}
sub parent {
my ($self) = @_;
return $self->{parent};
lib/App/ClusterSSH/Cluster.pm view on Meta::CPAN
$result = qx/ $command /;
$return_code = $CHILD_ERROR >> 8;
}
chomp($result);
$self->debug( 3, "Result: $result" );
$self->debug( 3, "Return code: $return_code" );
if ( $return_code != 0 ) {
croak(
App::ClusterSSH::Exception::Cluster->throw(
error => $self->loc(
"External command failure.\nCommand: [_1]\nReturn Code: [_2]",
$command,
$return_code,
),
)
);
}
my @results = split / /, $result;
lib/App/ClusterSSH/Config.pm view on Meta::CPAN
if ( exists $self->{$config} ) {
$self->{$config} = $args{$config};
}
else {
push( @unknown_config, $config );
}
}
if (@unknown_config) {
croak(
App::ClusterSSH::Exception::Config->throw(
unknown_config => \@unknown_config,
error => $self->loc(
'Unknown configuration parameters: [_1]' . $/,
join( ',', @unknown_config )
)
)
);
}
if ( !$self->{comms} ) {
croak(
App::ClusterSSH::Exception::Config->throw(
error => $self->loc( 'Invalid variable: comms' . $/ ),
),
);
}
if ( !$self->{ $self->{comms} } ) {
croak(
App::ClusterSSH::Exception::Config->throw(
error => $self->loc(
'Invalid variable: [_1]' . $/,
$self->{comms}
),
),
);
}
# check the terminal has been found correctly
# looking for the terminal should not be fatal
lib/App/ClusterSSH/Config.pm view on Meta::CPAN
return $self;
}
sub parse_config_file {
my ( $self, $config_file ) = @_;
$self->debug( 2, 'Loading in config file: ', $config_file );
# if ( !-e $config_file || !-r $config_file ) {
# croak(
# App::ClusterSSH::Exception::Config->throw(
# error => $self->loc(
# 'File [_1] does not exist or cannot be read' . $/,
# $config_file
# ),
# ),
# );
# }
#
# open( CFG, $config_file ) or die("Couldnt open $config_file: $!");
# my $l;
lib/App/ClusterSSH/Config.pm view on Meta::CPAN
sub write_user_config_file {
my ($self) = @_;
# attempt to move the old config file to one side
if ( -f "$ENV{HOME}/.csshrc" ) {
eval { move( "$ENV{HOME}/.csshrc", "$ENV{HOME}/.csshrc.DISABLED" ) };
if ($@) {
croak(
App::ClusterSSH::Exception::Config->throw(
error => $self->loc(
'Unable to move [_1] to [_2]: [_3]' . $/,
'$HOME/.csshrc', '$HOME/.csshrc.DISABLED', $@
),
)
);
}
else {
warn(
$self->loc(
lib/App/ClusterSSH/Config.pm view on Meta::CPAN
),
);
}
}
return if ( -f "$ENV{HOME}/.clusterssh/config" );
if ( !-d "$ENV{HOME}/.clusterssh" ) {
if ( !mkdir("$ENV{HOME}/.clusterssh") ) {
croak(
App::ClusterSSH::Exception::Config->throw(
error => $self->loc(
'Unable to create directory [_1]: [_2]' . $/,
'$HOME/.clusterssh', $!
),
),
);
}
}
lib/App/ClusterSSH/Config.pm view on Meta::CPAN
print $fh '# '
. $self->loc('Tag definitions moved from old .csshrc file'),
$/;
foreach ( sort( keys(%old_clusters) ) ) {
print $fh $_, ' ', join( ' ', $old_clusters{$_} ), $/;
}
close($fh);
}
else {
croak(
App::ClusterSSH::Exception::Config->throw(
error => $self->loc(
'Unable to write [_1]: [_2]' . $/,
'$HOME/.clusterssh/clusters',
$!
),
),
);
}
}
lib/App/ClusterSSH/Config.pm view on Meta::CPAN
close(CONFIG);
warn(
$self->loc(
'Created new configuration file within [_1]' . $/,
'$HOME/.clusterssh/'
)
);
}
else {
croak(
App::ClusterSSH::Exception::Config->throw(
error => $self->loc(
'Unable to write default [_1]: [_2]' . $/,
'$HOME/.clusterssh/config', $!
),
),
);
}
return $self;
}
lib/App/ClusterSSH/Config.pm view on Meta::CPAN
return $path;
}
# could use File::Which for some of this but we also search a few other places
# just in case $PATH isnt set up right
sub find_binary {
my ( $self, $binary ) = @_;
if ( !$binary ) {
croak(
App::ClusterSSH::Exception::Config->throw(
error => $self->loc('argument not provided') . $/,
),
);
}
$self->debug( 2, "Looking for $binary" );
# if not found, strip the path and look again
if ( $binary =~ m!^/! ) {
if ( -f $binary ) {
lib/App/ClusterSSH/Config.pm view on Meta::CPAN
);
}
}
else {
$self->debug( 2, "Already configured OK" );
$path = $binary;
}
if ( !$path || !-f $path || !-x $path ) {
croak(
App::ClusterSSH::Exception::Config->throw(
error => $self->loc(
'"[_1]" binary not found - please amend $PATH or the cssh config file'
. $/,
$binary
),
),
);
}
chomp($path);
lib/App/ClusterSSH/Getopt.pm view on Meta::CPAN
$self->add_common_options;
return $self;
}
sub add_option {
my ( $self, %args ) = @_;
my $spec = $args{spec};
if ( !$spec ) {
croak(
App::ClusterSSH::Exception::Getopt->throw(
error => 'No "spec" passed to add_option',
),
);
}
my ( $option, $arg ) = $spec =~ m/^(.*?)(?:[\+=:](.*))?$/;
if ($arg) {
my $arg_open = '<';
my $arg_close = '>';
if ( $args{arg_optional} ) {
$arg_open = '[';
lib/App/ClusterSSH/Helper.pm view on Meta::CPAN
}
sub script {
my ( $self, $config ) = @_;
if ( !defined $config
|| !ref $config
|| ref $config ne "App::ClusterSSH::Config" )
{
croak(
App::ClusterSSH::Exception::Helper->throw(
error => 'No configuration provided or in wrong format',
),
);
}
foreach my $arg ( "comms", $config->{comms}, $config->{comms} . '_args',
'command', 'auto_close' )
{
if ( !defined $config->{$arg} ) {
croak(
App::ClusterSSH::Exception::Helper->throw(
error => "Config '$arg' not provided",
),
);
}
}
my $comms = $config->{ $config->{comms} };
my $comms_args = $config->{ $config->{comms} . '_args' };
my $config_command = $config->{command};
my $autoclose = $config->{auto_close};
lib/App/ClusterSSH/Host.pm view on Meta::CPAN
use base qw/ App::ClusterSSH::Base /;
our %ssh_hostname_for;
our %ssh_configs_read;
sub new {
my ( $class, %args ) = @_;
if ( !$args{hostname} ) {
croak(
App::ClusterSSH::Exception->throw(
error => $class->loc('hostname is undefined')
)
);
}
# remove any keys undef values - must be a better way...
foreach my $remove (qw/ port username geometry /) {
if ( !$args{$remove} && grep {/^$remove$/} keys(%args) ) {
delete( $args{$remove} );
}
lib/App/ClusterSSH/Host.pm view on Meta::CPAN
username => $username,
hostname => $host_string,
port => $port,
geometry => $geometry,
type => 'ipv6',
);
}
# if we got this far, we didnt parse the host_string properly
croak(
App::ClusterSSH::Exception->throw(
error => $self->loc(
'Unable to parse hostname from "[_1]"', $host_string
)
)
);
}
sub check_ssh_hostname {
my ( $self, ) = @_;