diff options
Diffstat (limited to 'drakwizard.pl')
-rwxr-xr-x | drakwizard.pl | 137 |
1 files changed, 126 insertions, 11 deletions
diff --git a/drakwizard.pl b/drakwizard.pl index 0470bbf5..456da9a5 100755 --- a/drakwizard.pl +++ b/drakwizard.pl @@ -20,7 +20,7 @@ use lib qw(/usr/lib/libDrakX); use strict; -use vars qw($Wizard_title $Wizard_pix_up $lib_script $perl_module %variable $in $rpm %chooser_hash $welcome $perl_module_name $verbose %description); +use vars qw($Wizard_title $Wizard_pix_up $lib_script $perl_module %variable $in $rpm %chooser_hash $welcome $perl_module_name $verbose %description $summary); use XML::Parser; use standalone; @@ -35,7 +35,6 @@ my $in = 'interactive'->vnew('su', 'default'); $::direct = /-direct/; $::Wizard_no_previous = 1; $::Wizard_title = "Drakwizard"; -$::isWizard = 1; my $standalone = 1; ! -r '/etc/sysconfig/network-scripts/drakconnect_conf' && @@ -70,15 +69,23 @@ if (!defined($ARGV[0])) { my $o = []; my $xmltree = XML::Parser->new(Style => 'Tree')->parsefile($ARGV[0]); -get_parameter($o, $xmltree); -if (("@ARGV" =~ /--debug/)) { +local $_ = join '', @ARGV; + if (/-debug/) { $::verbose = 1; - navigation($o, $o->[0]); +} + +if (/-summary/) { + get_summary($o, $xmltree); + summary($o); } else { - no warnings; - $::verbose = 0; - eval { navigation($o, $o->[0]) }; + $::isWizard = 1; + get_parameter($o, $xmltree); + if (!$::verbose) { + no warnings; + eval { navigation($o, $o->[0]) }; + } + else { navigation($o, $o->[0]) }; } $in->exit; @@ -137,6 +144,7 @@ sub get_parameter { $leaf->{helpText} = $leaf->{helpText} ? "$leaf->{helpText}\n$leaf->{helpText}" : "$leaf->{helpText}\n"; } $page->{info} = $leaf->{helpText} ? "$page->{info}\n$leaf->{helpText}" : "$page->{info}\n"; + $page->{info} = c::from_utf8($page->{info}); if ($leaf->{fillScript}) { $page->{info} .= translate(`source $lib_script; $leaf->{fillScript}`); } @@ -161,7 +169,7 @@ sub get_parameter { $description{$leaf->{value}} = $leaf->{description}; }); $actions{$tag} and &{$actions{$tag}}; - }elsif($leaf=~ /\w\D/){ + } elsif($leaf=~ /\w\D/){ $tag = $leaf; } } @@ -231,7 +239,7 @@ sub display { : { label => $_->{helpText}, val => \$ENV{$variable{$_->{variableName}}}, list => [@liste], type => $_->{main_order} }; } @{$page->{freetext}}; - if($page->{executionLevel} eq 'NORMAL') { + if ($page->{executionLevel} eq 'NORMAL') { $in->ask_from($page->{name}, translate($page->{info}), \@data) or navigation($o, $page->{old_page}); foreach(@{$page->{freetext}}) { @@ -269,7 +277,7 @@ sub navigation { if ($page->{Target}->{jumpIndex}) { $? = $? >> 8; find_page($o, $page->{Target}->{jumpIndex}->{$?}), $page; - } + } else { $page->{next_page}, $page; } @@ -292,3 +300,110 @@ sub navigation { }; navigation($o, $next, $prev); } + +sub get_summary { + my ($o, $tree, $tag, $page) = @_; + + foreach my $leaf (@$tree) { + if (ref($leaf) eq 'ARRAY') { + $page = get_summary($o, $leaf, $tag, $page); + } elsif (ref($leaf) eq 'HASH') { + my $common_freetext_chooser; + my %actions = ( + Wizard => sub { + ($Wizard_title, $lib_script, $perl_module, $rpm, $Wizard_pix_up) = @{$leaf}{qw(wizardTitle libScript perlModule rpm defaultImage)}; + if ($rpm) { + if (!$in->do_pkgs->is_installed($rpm)) { + if ($in->ask_okcancel("error", _("%s is not installed\nClick \"Next\" to install or \"Cancel\" to quit", c::from_utf8($rpm)))) { + if (!$in->do_pkgs->install($rpm eq 'bind' ? 'bind-9' : $rpm)) { + $::Wizard_finished = 1; + $in->ask_okcancel("error", _("installation failed")); + $in->exit; + } + } + else { $in->exit } + } + } + if ($perl_module) { + ($::perl_module_name) = ($perl_module =~ /.*\/(.*)\.pm/); + require $perl_module; + } + }, + Variable => sub { + $variable{$leaf->{name}} = $leaf->{shellVariable}; + $ENV{$variable{$leaf->{name}}} = $leaf->{defaultValue}; + }, + Page => sub { + push @{$summary->{freetext}}, { $leaf, main_order => 'separator'}; + push @$o, $page = { %$leaf }; + }, + Target => sub { + $page->{Target}->{jumpIndex}->{$leaf->{jumpIndex}} = $leaf->{targetName}; + }, + Freetext => $common_freetext_chooser = sub { + push @{$summary->{freetext}}, { %$leaf, main_order => + (($tag eq 'Chooser') ? 'combo' + : ($tag eq 'Boolean') ? 'bool' + : ($leaf->{editable} eq 'true') ? 'entry' + : 'field')}; + }, + Chooser => \&$common_freetext_chooser, + Boolean => \&$common_freetext_chooser, + Option => sub { + push @{${$summary->{freetext}}[-1]->{Option}}, $leaf->{description}; + $chooser_hash{$leaf->{description}} = $leaf->{value}; + $description{$leaf->{value}} = $leaf->{description}; + }); + $actions{$tag} and &{$actions{$tag}}; + } elsif ($leaf=~ /\w\D/){ + $tag = $leaf; + } + } + $page; +} + +sub summary { + my $valeur; + my @liste; + my @data = map { + if ($_->{main_order} eq 'combo') { + if($_->{fillScript}){ + @liste = (); + $valeur = `. $lib_script && $_->{fillScript}`; + while( $valeur =~ /(.+)\n/g){ + push @liste, $1; + $chooser_hash{$1} = $1; + } + } + else { + @liste = @{$_->{Option}}; + } + } + if ($_->{fillScript}) { + $ENV{$variable{$_->{variableName}}} = `. $lib_script && $_->{fillScript}`; + } + elsif (!$ENV{$variable{$_->{variableName}}} && $_->{fillfunc}) { + $ENV{$variable{$_->{variableName}}} = $::{$perl_module_name."::"}{"$_->{fillfunc}"}->(); + } + chomp($ENV{$variable{$_->{variableName}}}); + $ENV{$_->{variableName}} = $ENV{$variable{$_->{variableName}}}; + ($_->{main_order} eq 'entry') ? { label => _($_->{helpText}), + val => \$ENV{$variable{$_->{variableName}}}, type => $_->{main_order} } + : ($_->{main_order} eq 'bool') ? { val => \$ENV{$variable{$_->{variableName}}}, type => $_->{main_order}, + text => translate($_->{helpText}) } + : ($_->{main_order} eq 'separator') ? { type => $_->{main_order}} + : { label => $_->{helpText}, val => \$ENV{$variable{$_->{variableName}}}, + list => [@liste], type => $_->{main_order} } + } @{$summary->{freetext}}; + $in->ask_from("summary", "info", \@data); + foreach(@{$summary->{freetext}}) { + if($_->{main_order} eq 'bool') { + $ENV{$variable{$_->{variableName}}} = $ENV{$variable{$_->{variableName}}} ? 1 : 0; + $description{$ENV{$variable{$_->{variableName}}}} = $ENV{$variable{$_->{variableName}}} ? _("enabled") : _("disabled"); + } + elsif ($_->{main_order} eq 'combo') { + $ENV{$variable{$_->{variableName}}} = $chooser_hash{$ENV{$variable{$_->{variableName}}}}; + } + } + undef $::Wizard_no_previous; +} |