From 9f321f9b699d8b24341c217f3f0ef2f66686d6b0 Mon Sep 17 00:00:00 2001 From: Arnaud Desmons Date: Fri, 4 Oct 2002 10:05:36 +0000 Subject: shortcuts --- drakwizard.pl | 235 +++++++++++++++++++++++----------------------------------- 1 file changed, 91 insertions(+), 144 deletions(-) diff --git a/drakwizard.pl b/drakwizard.pl index 456da9a5..5e9cd572 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 $summary); +use vars qw($Wizard_title $Wizard_pix_up $lib_script $perl_module %variable $in $rpm %chooser_hash $welcome $perl_module_name $verbose %description $summary $summary_func); use XML::Parser; use standalone; @@ -74,12 +74,14 @@ local $_ = join '', @ARGV; $::verbose = 1; } +$::isWizard = 1; + if (/-summary/) { get_summary($o, $xmltree); - summary($o); + my $data = map_freetext($summary->{freetext}); + $in->ask_from("summary", "info", $data); } else { - $::isWizard = 1; get_parameter($o, $xmltree); if (!$::verbose) { no warnings; @@ -92,6 +94,72 @@ $in->exit; sub member { my $e = shift; foreach (@_) { $e eq $_ and return 1 } 0 } +sub load_wizard { + ($Wizard_title, $lib_script, $perl_module, $rpm, $Wizard_pix_up, $summary_func) = @_; + 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; + } +} + +sub push_options { + my ($leaf) = @_; + $chooser_hash{$leaf->{description}} = $leaf->{value}; + $description{$leaf->{value}} = $leaf->{description}; +} + +sub map_freetext { + my @liste; + my $valeur; + + 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}}}; + if ($_->{main_order} eq 'entry') { + { label => _($_->{helpText}), + val => \$ENV{$variable{$_->{variableName}}}, type => $_->{main_order} } } + elsif ($_->{main_order} eq 'bool') { { val => \$ENV{$variable{$_->{variableName}}}, + type => $_->{main_order}, + text => translate($_->{helpText}) } } + elsif ($_->{main_order} eq 'combo') { + { label => $_->{helptext}, val => \$ENV{$variable{$_->{variableName}}}, + list => [@liste], type => $_->{main_order} } + } + } @{$_[0]}; + \@data; +} + sub get_parameter { my ($o, $tree, $tag ,$page) = @_; @@ -101,25 +169,8 @@ sub get_parameter { } 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; - } - }, + Wizard => sub { + load_wizard(@{$leaf}{qw(wizardTitle libScript perlModule rpm defaultImage)}) },, Variable => sub { $variable{$leaf->{name}} = $leaf->{shellVariable}; $ENV{$variable{$leaf->{name}}} = $leaf->{defaultValue}; @@ -156,13 +207,13 @@ sub get_parameter { }, Freetext => $common_freetext_chooser = sub { push @{$page->{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, + (($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 @{${$page->{freetext}}[-1]->{Option}}, $leaf->{description}; $chooser_hash{$leaf->{description}} = $leaf->{value}; @@ -176,7 +227,6 @@ sub get_parameter { $page; } - sub find_page { my ($o, $name) = @_; $_->{name} eq $name and return $_ foreach @$o; @@ -205,43 +255,10 @@ sub display { else { 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 'field') ? { val => - $description{$ENV{$variable{$_->{variableName}}}}? - $description{$ENV{$variable{$_->{variableName}}}} : - $ENV{$variable{$_->{variableName}}}, - label => $_->{helpText} } - : { label => $_->{helpText}, val => \$ENV{$variable{$_->{variableName}}}, - list => [@liste], type => $_->{main_order} }; - } @{$page->{freetext}}; if ($page->{executionLevel} eq 'NORMAL') { - $in->ask_from($page->{name}, translate($page->{info}), - \@data) or navigation($o, $page->{old_page}); + my $data = map_freetext($page->{freetext}); + $in->ask_from($page->{name}, translate($page->{info}), + $data) or navigation($o, $page->{old_page}); foreach(@{$page->{freetext}}) { if($_->{main_order} eq 'bool') { $ENV{$variable{$_->{variableName}}} = $ENV{$variable{$_->{variableName}}} ? 1 : 0; @@ -311,44 +328,20 @@ sub get_summary { 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; - } - }, + load_wizard(@{$leaf}{qw(wizardTitle libScript perlModule rpm defaultImage summary_func)}) }, 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, + (($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}; @@ -361,49 +354,3 @@ sub get_summary { } $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; -} -- cgit v1.2.1