diff options
author | Antoine Ginies <aginies@mandriva.com> | 2005-09-01 11:55:10 +0000 |
---|---|---|
committer | Antoine Ginies <aginies@mandriva.com> | 2005-09-01 11:55:10 +0000 |
commit | 776cc0880fa73c52637e321bcf2c2af0fc794e90 (patch) | |
tree | 593b47a8f58c3bc683b76c35d83a53b4b06e9514 | |
parent | fc501232ab50d7b4e5aa1441d76515f4de1d275f (diff) | |
download | drakpxelinux-776cc0880fa73c52637e321bcf2c2af0fc794e90.tar drakpxelinux-776cc0880fa73c52637e321bcf2c2af0fc794e90.tar.gz drakpxelinux-776cc0880fa73c52637e321bcf2c2af0fc794e90.tar.bz2 drakpxelinux-776cc0880fa73c52637e321bcf2c2af0fc794e90.tar.xz drakpxelinux-776cc0880fa73c52637e321bcf2c2af0fc794e90.zip |
various change in systems tab
-rw-r--r-- | drakpxelinux.pl | 111 |
1 files changed, 94 insertions, 17 deletions
diff --git a/drakpxelinux.pl b/drakpxelinux.pl index 4fcb8ba..aab66c6 100644 --- a/drakpxelinux.pl +++ b/drakpxelinux.pl @@ -57,6 +57,7 @@ our $treeview = Gtk2::TreeView->new_with_model($model); my $SYSLINUXPATH = '/usr/lib/syslinux/'; my $MEMDISK = $SYSLINUXPATH . '/memdisk'; my $XINETDDIR = "/etc/xinetd.d"; +my $conf_mac_profiles_name = "/var/lib/tftpboot/X86PC/conf_mac_profiles"; my $net = {}; network::network::read_net_conf($net); @@ -858,8 +859,8 @@ my $profiles_conf = network::pxe::read_profiles(); sub create_systems_list() { my $systems = Gtk2::SimpleList->new( N("MAC address") => 'text', - N("Installed") => 'bool', N("Profil 1") => 'text', + N("Profil 2") => 'text', N("Computer Name") => 'text', ); foreach ($systems->get_columns) { $_->set_resizable(1); } @@ -872,6 +873,11 @@ sub create_systems_list() { } #- don't let the user modify the "Installed" state $systems->get_column(1)->get_cell_renderers->set_property('mode', 'inert'); + my $col = $systems->get_column(3); # la colonne NOM, colonne numéro 2 + $systems->get_column(3)->signal_connect('clicked', sub { + write_profile_conf($systems); + } + ); $systems->set_column_editable(3, 1); $systems->set_rules_hint(1); return $systems; @@ -902,7 +908,7 @@ my $log_text = gtknew('TextView'); sub get_selected_profile() { my $model_profiles = $profiles->get_model; my $iter = $profiles->get_selection->get_selected; - my $profile = $model_profiles->get($iter, 0); + $iter and my $profile = $model_profiles->get($iter, 0); return $profile; } @@ -916,22 +922,76 @@ sub get_pxelinux_conf_from_profile() { } } -sub system_entry_set_profile { my ($entry, $profile) = @_; $entry->[2] = $profile || N("None") } -sub system_entry_set_installed { my ($entry, $state) = @_; $entry->[1] = $state } +sub system_entry_set_profile2 { + my ($entry, $profile) = @_; + $entry->[2] = $profile || N("None"); +} + +sub system_entry_set_profile { + my ($entry, $profile) = @_; + $entry->[1] = $profile || N("None"); +} + +sub system_entry_set_name { + my ($entry, $name) = @_; + $entry->[3] = $name || ""; +} sub find_system_entry_for_mac_address { my ($mac_address) = @_; find { $_->[0] eq $mac_address } @{$systems->{data}}; } +sub get_name_from_mac { + my ($mac) = @_; + foreach (cat_($conf_mac_profiles_name)) { + my $name = $1 if m/$mac\|\w+\|\w+\|(\w+)/; + $name and return $name; + } +} + +sub get_profile2_from_mac { + my ($mac) = @_; + foreach (cat_($conf_mac_profiles_name)) { + my $profile = $1 if m/$mac\|\w+\|(\w+)\|\w+/; + print $profile; + $profile and return $profile; + } +} + +sub update_systems_data { + my ($systems) = @_; + foreach $a (@{$systems->{data}}) { + my $mac = $a->[0]; + my $name = get_name_from_mac($mac); + my $profile = get_profile2_from_mac($mac); + my $entry = [ $mac ]; + + foreach (cat_($conf_mac_profiles_name)) { + my $name if m/$mac\|\w+\|\w+\|(\w+)/; + my $profile if m/$mac\|\w+\|(\w+)\|\w+/; + print " $mac name $name\n"; + print " $mac profile $profile\n"; + } + system_entry_set_name($entry, $name); + system_entry_set_profile2($entry, $profile); + } +} + sub add_configured_mac_addresses() { - while (my ($mac_address, $conf) = each %{$profiles_conf->{per_mac}}) { - my $entry = [ $mac_address ]; - system_entry_set_profile($entry, $conf->{profile}); - system_entry_set_installed($entry, !$conf->{to_install}); - push @{$systems->{data}}, $entry; - gtktext_append($log_text, "Detected new system: $mac_address\n"); - } + my ($name, $profile2); + while (my ($mac_address, $conf) = each %{$profiles_conf->{per_mac}}) { + my $entry = [ $mac_address ]; + system_entry_set_profile($entry, $conf->{profile}); +# $name = get_name_from_mac($mac_address); +# $profile2 = get_profile2_from_mac($mac_address); +# system_entry_set_name($entry, $conf->{name}); +# system_entry_set_profile2($entry, $conf->{profile2}); + push @{$systems->{data}}, $entry; +# write_profile_conf($systems); + gtktext_append($log_text, "Detected new system: $mac_address\n"); + } + update_systems_data($systems); } sub get_mac_addresses_from_dhcp_log() { @@ -977,11 +1037,19 @@ sub add_profile() { $w->main; } +sub write_profile_conf { + print "write_conf\n"; + my ($systems) = @_; + my ($mac, $profile, $profile2, $name); + output($conf_mac_profiles_name, "# auto generated by drakpxelinux\n"); + foreach $a (@{$systems->{data}}) { + append_to_file($conf_mac_profiles_name, "$a->[0]|$a->[1]|$a->[2]|$a->[3]\n"); + } +} + ############### # Main Program ############### -# create model - sub profile_selected { my ($profile) = @_; @@ -1140,15 +1208,25 @@ gtkpack($w->{window}, gtknew('VBox', spacing => 0, children => [ 1, gtknew('ScrolledWindow', child => $systems), 0, gtknew('HBox', children_loose => [ - # gtknew('Button', text => N("Scan for systems")), - gtksignal_connect(gtknew('Button', text => N("Set system")), clicked => sub { + gtksignal_connect(gtknew('Button', text => N("Set Profile 1")), clicked => sub { my $profile = $profiles_combo->get_active_text; my $to_install = exists $profiles_conf->{profiles}{install}{$profile}; foreach ($systems->get_selected_indices) { my $entry = $systems->{data}[$_]; network::pxe::set_profile_for_mac_address($profile, $to_install, $entry->[0]); - system_entry_set_installed($entry, 0); system_entry_set_profile($entry, $profile); + update_systems_data($systems); + write_profile_conf($systems); + } + }), + gtksignal_connect(gtknew('Button', text => N("Set Profile 2")), clicked => sub { + my $profile = $profiles_combo->get_active_text; + my $to_install = exists $profiles_conf->{profiles}{install}{$profile}; + foreach ($systems->get_selected_indices) { + my $entry = $systems->{data}[$_]; + system_entry_set_profile2($entry, $profile); + update_systems_data($systems); + write_profile_conf($systems); } }), $profiles_combo = gtknew('ComboBox'), @@ -1169,5 +1247,4 @@ Glib::Timeout->add(60000, \&get_mac_addresses_from_dhcp_log); refresh_profiles(); $w->show; -#$W->show_all; Gtk2->main; |