From 81a79902b69192f67b51cec697d996251d2ba83f Mon Sep 17 00:00:00 2001 From: Duncan Ferguson Date: Mon, 11 Jul 2011 22:07:57 +0100 Subject: [PATCH] Further work on config module --- lib/App/ClusterSSH/Config.pm | 21 +++++++++++-- t/15config.t | 35 +++++++++++++++------ t/15config.t.file3 | 60 ++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 12 deletions(-) create mode 100644 t/15config.t.file3 diff --git a/lib/App/ClusterSSH/Config.pm b/lib/App/ClusterSSH/Config.pm index 80133df..86543da 100644 --- a/lib/App/ClusterSSH/Config.pm +++ b/lib/App/ClusterSSH/Config.pm @@ -10,6 +10,8 @@ use Carp; use base qw/ App::ClusterSSH::Base /; +my %clusters; +my @app_specific = ( qw/ title comms method ssh rsh telnet ccon / ); my %default_config = ( terminal => "xterm", terminal_args => "", @@ -82,6 +84,8 @@ sub validate_args { my @unknown_config = (); foreach my $config ( sort( keys(%args) ) ) { + next if grep /$config/, @app_specific; + if ( exists $self->{$config} ) { $self->{$config} = $args{$config}; } @@ -110,10 +114,10 @@ sub parse_config_file { $self->debug( 2, 'Loading in config file: ', $config_file ); - if ( !-e $config_file || !-r $config_file ){ + if ( !-e $config_file || !-r $config_file ) { croak( App::ClusterSSH::Exception::Config->throw( - error => $self->loc( + error => $self->loc( 'File [_1] does not exist or cannot be read', $config_file ), ), @@ -146,8 +150,19 @@ sub parse_config_file { } close(CFG); + # grab any clusters from the config before validating it + if ( $read_config{clusters} ) { + carp("TODO - deal with clusters"); + $self->debug( 3, "Picked up clusters defined in $config_file" ); + foreach my $cluster ( sort split / /, $read_config{clusters} ) { + delete( $read_config{$cluster} ); + } + delete( $read_config{clusters} ); + } + # tidy up entries, just in case - $read_config{terminal_font} =~ s/['"]//g if($read_config{terminal_font}); + $read_config{terminal_font} =~ s/['"]//g + if ( $read_config{terminal_font} ); $self->validate_args(%read_config); } diff --git a/t/15config.t b/t/15config.t index 2d5094b..7bb3797 100644 --- a/t/15config.t +++ b/t/15config.t @@ -114,7 +114,7 @@ is( $trap->die, undef, 'validated ok' ); isa_ok( $config, "App::ClusterSSH::Config" ); is_deeply( $config, \%expected, 'default config is correct' ); -$config = App::ClusterSSH::Config->new(); +$config = App::ClusterSSH::Config->new(); %expected = %default_config; my $file = "$Bin/$Script.doesntexist"; @@ -129,12 +129,12 @@ is( $trap->die, $file = "$Bin/$Script.file1"; note("using $file"); -$config = App::ClusterSSH::Config->new(); -%expected = %default_config; -$expected{screen_reserve_left}=100; -$expected{screen_reserve_right}=100; -$expected{screen_reserve_top}=100; -$expected{screen_reserve_bottom}=160; +$config = App::ClusterSSH::Config->new(); +%expected = %default_config; +$expected{screen_reserve_left} = 100; +$expected{screen_reserve_right} = 100; +$expected{screen_reserve_top} = 100; +$expected{screen_reserve_bottom} = 160; trap { $config = $config->parse_config_file( $file, ); }; @@ -147,16 +147,33 @@ is_deeply( $config, \%expected, 'amended config is correct' ); $file = "$Bin/$Script.file2"; note("using $file"); -$config = App::ClusterSSH::Config->new(); +$config = App::ClusterSSH::Config->new(); %expected = %default_config; trap { $config = $config->parse_config_file( $file, ); }; is( $trap->leaveby, 'die', 'died ok' ); isa_ok( $trap->die, 'App::ClusterSSH::Exception::Config' ); -isa_ok( $config, "App::ClusterSSH::Config" ); +isa_ok( $config, "App::ClusterSSH::Config" ); is( $trap->stdout, q{}, 'Expecting no STDOUT' ); is( $trap->stderr, q{}, 'Expecting no STDERR' ); is_deeply( $config, \%expected, 'amended config is correct' ); +$file = "$Bin/$Script.file3"; +note("using $file"); +$config = App::ClusterSSH::Config->new(); +%expected = %default_config; +trap { + $config = $config->parse_config_file( $file, ); +}; + +is( $trap->leaveby, 'return', 'returned ok' ); +is( $trap->die, undef, 'returned ok' ); +isa_ok( $config, "App::ClusterSSH::Config" ); +is( $trap->stdout, q{}, 'Expecting no STDOUT' ); +{ + local $TODO = "deal with cluster definitions in config file"; + is( $trap->stderr, q{}, 'Expecting no STDERR' ); +} + done_testing(); diff --git a/t/15config.t.file3 b/t/15config.t.file3 new file mode 100644 index 0000000..ed06c2a --- /dev/null +++ b/t/15config.t.file3 @@ -0,0 +1,60 @@ +# Configuration dump produced by 'cssh -u' +auto_quit=yes +clusters=duncs test fred duncs1 fred1 test1 test2 test3 test4 test5 live test dev kvm +command= +comms=ssh +console_position= +extra_cluster_file= +history_height=10 +history_width=40 +key_addhost=Control-Shift-plus +key_clientname=Alt-n +key_history=Alt-h +key_paste=Control-v +key_quit=Control-q +key_retilehosts=Alt-r +max_host_menu_items=30 +method=ssh +mouse_paste=Button-2 +rsh_args= +screen_reserve_bottom=60 +screen_reserve_left=0 +screen_reserve_right=0 +screen_reserve_top=0 +show_history=0 +ssh=/usr/bin/ssh +ssh_args= -x -o ConnectTimeout=10 +telnet_args= +terminal=/usr/bin/xterm +terminal_allow_send_events=-xrm '*.VT100.allowSendEvents:true' +terminal_args= +terminal_bg_style=dark +terminal_colorize=1 +terminal_decoration_height=10 +terminal_decoration_width=8 +terminal_font=6x13 +terminal_reserve_bottom=0 +terminal_reserve_left=5 +terminal_reserve_right=0 +terminal_reserve_top=5 +terminal_size=80x24 +terminal_title_opt=-T +title=CSSH +unmap_on_redraw=no +use_hotkeys=yes +window_tiling=yes +window_tiling_direction=right +duncs=orion +test=macbook +fred=duncs test +duncs1=orion +test1=macbook +fred1=duncs test +test2=macbook +test3=macbook +test4=macbook +test5=macbook +live = live1 live2 live3 \ + live4 live 5 live 6 +test=test1 test2 test3 test4 +dev=dev1 dev2 dev3 dev4