summaryrefslogtreecommitdiffstats
path: root/drakwizard.pl
diff options
context:
space:
mode:
authorArnaud Desmons <adesmons@mandriva.com>2002-07-26 08:48:33 +0000
committerArnaud Desmons <adesmons@mandriva.com>2002-07-26 08:48:33 +0000
commit1f50db231abebdf1d547e0120e3fb65ce8a93b65 (patch)
tree4109ed6d382622e2853439d0a1f34bf393e3ae94 /drakwizard.pl
parentccafd1b525da6ba7ee9b3bb02b882cb9a747c343 (diff)
downloaddrakwizard-1f50db231abebdf1d547e0120e3fb65ce8a93b65.tar
drakwizard-1f50db231abebdf1d547e0120e3fb65ce8a93b65.tar.gz
drakwizard-1f50db231abebdf1d547e0120e3fb65ce8a93b65.tar.bz2
drakwizard-1f50db231abebdf1d547e0120e3fb65ce8a93b65.tar.xz
drakwizard-1f50db231abebdf1d547e0120e3fb65ce8a93b65.zip
new launcher allow perlModule loading
Diffstat (limited to 'drakwizard.pl')
-rwxr-xr-xdrakwizard.pl190
1 files changed, 190 insertions, 0 deletions
diff --git a/drakwizard.pl b/drakwizard.pl
new file mode 100755
index 00000000..34065b02
--- /dev/null
+++ b/drakwizard.pl
@@ -0,0 +1,190 @@
+#!/usr/bin/perl
+
+# Wizdrake
+
+# Copyright (C) 2002 MandrakeSoft Mael Dodin (mdodin@mandrakesoft.com)
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+use lib qw(/usr/lib/libDrakX);
+#use strict;
+use vars qw($wizard_title $lib_script $perl_module %variable $in);
+
+use XML::Parser;
+use standalone;
+use interactive;
+
+defined($ARGV[0]) or die "Usage: drakwizard *.wiz\n";
+my $in = 'interactive'->vnew('su', 'default');
+
+sub translate { $_[0] }
+
+sub member { my $e = shift; foreach (@_) { $e eq $_ and return 1 } 0 }
+
+sub get_parameter {
+ my ($o, $tree, $tag ,$page) = @_;
+
+ foreach my $leaf (@$tree) {
+ if (ref($leaf) eq 'ARRAY') {
+ $page = get_parameter($o, $leaf, $tag, $page);
+ } elsif (ref($leaf) eq 'HASH') {
+ my $common_freetext_chooser;
+ my %actions = (Wizard => sub {
+ ($wizard_title, $lib_script, $perl_module) = @{$leaf}{qw(wizardTitle libScript perlModule)};
+ },
+ Variable => sub {
+ $variable{$leaf->{name}} = $leaf->{shellVariable};
+ $ENV{$leaf->{shellVariable}} = $leaf->{defaultValue};
+ },
+ Page => sub {
+ my $old_page = $page;
+ push @$o, $page = { %$leaf };
+ $old_page->{next_page} = $page;
+ },
+ Target => sub {
+ $page->{Target}->{jumpIndex}->{$leaf->{jumpIndex}} = $leaf->{targetName};
+ },
+ Info => sub {
+ $page->{info} = $leaf->{helpText} ? "$page->{info} $leaf->{helpText}" : "$page->{info}\n";
+ $page->{info} =~ s/\\q/\"/g;
+ $page->{info} =~ s/\\a/\&/g;
+ },
+ Freetext => $common_freetext_chooser = sub {
+ push @{$page->{freetext}}, { %$leaf, main_order => ($tag eq 'Chooser') ? 'combo'
+ : (($tag eq 'Boolean') ? 'bool' : 'entry') };
+ },
+ Chooser => \&$common_freetext_chooser,
+
+ Boolean => \&$common_freetext_chooser,
+
+ Option => sub { push @{${$page->{freetext}}[-1]->{Option}}, $leaf->{value}.$leaf->{description};} );
+ $actions{$tag} and &{$actions{$tag}};
+ }elsif($leaf=~ /\w\D/){
+ $tag = $leaf;
+ }
+ }
+ return $page;
+}
+
+
+sub find_page {
+ my ($o, $name) = @_;
+ $_->{name} eq $name and return $_ foreach @$o;
+}
+
+sub display {
+ my ($o, $page) = @_;
+
+ if ( $page->{nextFinish} eq 'true') {
+ $::Wizard_no_previous = 1;
+ $in->ask_okcancel(translate($page->{name}),
+ translate($page->{info}), 1) or quit_global($in, 0);
+ $in->exit;
+ } elsif (!$page->{freetext}) {
+ $in->ask_okcancel(translate($page->{name}),
+ translate($page->{info}), 1) or navigation($o, $page->{old_page});
+ } else {
+ my $valeur;
+ my @liste;
+ my @data = map {
+ for ($_->{fillScript}) {
+ system("source $lib_script ; $_->{fillScript}");
+ }
+ if($_->{main_order} eq 'combo'){
+ if($_->{fillScript}){
+ $valeur = `$_->{fillScript}`;
+ while( $valeur =~ /(.+)\n/g ){
+ push @liste, $1;
+ }
+ }else{
+ @liste = @{$_->{Option}};
+ }
+ }
+ ($_->{main_order} eq 'entry') ? { label => translate($_->{helpText}),
+ val => \$ENV{$variable{$_->{variableName}}}, type => $_->{main_order} }
+ : ($_->{main_order} eq 'bool') ? { val => \$ENV{$variable{$_->{variableName}}}, type => $_->{main_order},
+ text => translate($_->{helpText}, advanced => 1) }
+ : { label => translate($_->{helpText}), val => \$ENV{$variable{$_->{variableName}}},
+ list => [@liste, ""], type => $_->{main_order} };
+ } @{$page->{freetext}};
+ if($page->{executionLevel} eq 'NORMAL'){
+
+ $in->ask_from(translate($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;
+ }
+ }
+ }
+ }
+ undef $::Wizard_no_previous;
+}
+
+sub navigation {
+ my ($o, $page, $previous_page) = @_;
+ $page->{old_page} ||= $previous_page;
+
+ if (defined $perl_module_name && $page->{func}) {
+ @func_arg = split(/\s/, $page->{func});
+ $::{$perl_module_name."::"}{"$func_arg[0]"}->($func_arg[1]);
+ }
+ display($o, $page);
+ if ($page->{jumpPage}) {
+ navigation($o, find_page($o, $page->{jumpPage}), $page->{old_page});
+ } else {
+ my ($next, $prev) = do {
+ if($page->{jumpScript}) {
+ system("source $lib_script ; $page->{jumpScript}");
+ if ($page->{Target}->{jumpIndex}) {
+# if(!$page->{Target}->{jumpIndex}->{0}){
+# $? = $? >> 8; #==0|2560 ? 10 : $?-255;
+# }
+ $? = $? >> 8;
+ find_page($o, $page->{Target}->{jumpIndex}->{$?}), $page;
+ }
+ else {
+ $page->{next_page}, $page->{old_page};
+ }
+ }
+ else {
+ $page->{next_page}, $page;
+ }
+ };
+ navigation($o, $next, $prev);
+ }
+}
+
+my $o = [];
+my $xmltree = XML::Parser->new(Style => 'Tree')->parsefile($ARGV[0]);
+
+get_parameter($o, $xmltree);
+
+if ($perl_module) {
+ require $perl_module;
+}
+
+if ($perl_module =~ /.*\/(.*)\.pm/) {
+ $::perl_module_name = $1;
+}
+
+!$::isEmbedded && $in->isa('interactive_gtk') and $::isWizard=1;
+$::Wizard_title = translate($wizard_title);
+$::Wizard_pix_up = "wiz_drakconnect.png";
+$::direct = /-direct/;
+$::Wizard_no_previous = 1;
+
+navigation($o, $o->[0]);