Browse Source

Move interactive stuff out of main function

tags/3.10
Bastian Blank 9 years ago
parent
commit
324261a693
1 changed files with 68 additions and 59 deletions
  1. +68
    -59
      tasksel.pl

+ 68
- 59
tasksel.pl View File

@@ -432,67 +432,18 @@ sub getopts {
return %ret;
}

sub main {
my %options=getopts();
my @tasks_remove;
my @tasks_install;

# Options that output stuff and don't need a full processed list of
# tasks.
if (exists $options{"task-packages"}) {
my @tasks=all_tasks();
foreach my $taskname (@{$options{"task-packages"}}) {
my $task=name_to_task($taskname, @tasks);
if ($task) {
print "$_\n" foreach task_packages($task);
}
}
exit(0);
}
elsif ($options{"task-desc"}) {
my $task=name_to_task($options{"task-desc"}, all_tasks());
if ($task) {
my $extdesc=join(" ", @{$task->{description}}[1..$#{$task->{description}}]);
print dgettext("debian-tasks", $extdesc)."\n";
exit(0);
}
else {
exit(1);
}
}
sub interactive {
my $options = shift;
my @tasks = @_;

# This is relatively expensive, get the full list of available tasks and
# mark them.
my @tasks=map { hide_enhancing_tasks($_) } map { task_test($_, $options{"new-install"}, 1, 0) }
grep { task_avail($_) } all_tasks();
if ($options{"list-tasks"}) {
map { $_->{_installed} = task_installed($_) } @tasks;
@tasks=getdescriptions(@tasks);
print "".($_->{_installed} ? "i" : "u")." ".$_->{task}."\t".$_->{shortdesc}."\n"
foreach order_for_display(grep { $_->{_display} } @tasks);
exit(0);
}
if (! $options{"new-install"}) {
if (! $options->{"new-install"}) {
# Don't install hidden tasks if this is not a new install.
map { $_->{_install} = 0 } grep { $_->{_display} == 0 } @tasks;
}
if ($options{"install"}) {
my $task=name_to_task($options{"install"}, @tasks);
$task->{_install} = 1 if $task;
}
if ($options{"remove"}) {
my $task=name_to_task($options{"remove"}, @tasks);
push @tasks_remove, $task;
}
# The interactive bit.
my $interactive=0;

my @list = order_for_display(grep { $_->{_display} == 1 } @tasks);
if (@list && ! $options{install} && ! $options{remove}) {
$interactive=1;
if (! $options{"new-install"}) {
if (@list) {
if (! $options->{"new-install"}) {
# Find tasks that are already installed.
map { $_->{_installed} = task_installed($_) } @list;
# Don't install new tasks unless manually selected.
@@ -505,7 +456,7 @@ sub main {
map { $_->{_installed} = 0 } @list;
}
my $question="tasksel/tasks";
if ($options{"new-install"}) {
if ($options->{"new-install"}) {
$question="tasksel/first";
}
my @default = grep { $_->{_display} == 1 && ($_->{_install} == 1 || $_->{_installed} == 1) } @tasks;
@@ -541,7 +492,7 @@ sub main {
}
foreach my $task (@list) {
if (! $task->{_selected} && $task->{_installed}) {
push @tasks_remove, $task;
$task->{_remove} = 1;
}
}
}
@@ -581,7 +532,7 @@ sub main {
# mark them for install.
if (! exists $tested{$task->{task}}) {
$ENV{TESTING_ENHANCER}=1;
task_test($task, $options{"new-install"}, 0, 1);
task_test($task, $options->{"new-install"}, 0, 1);
delete $ENV{TESTING_ENHANCER};
$tested{$task->{task}}=$task->{_install};
}
@@ -602,8 +553,66 @@ sub main {
}
}

}

sub main {
my %options=getopts();
my @tasks_remove;
my @tasks_install;

# Options that output stuff and don't need a full processed list of
# tasks.
if (exists $options{"task-packages"}) {
my @tasks=all_tasks();
foreach my $taskname (@{$options{"task-packages"}}) {
my $task=name_to_task($taskname, @tasks);
if ($task) {
print "$_\n" foreach task_packages($task);
}
}
exit(0);
}
elsif ($options{"task-desc"}) {
my $task=name_to_task($options{"task-desc"}, all_tasks());
if ($task) {
my $extdesc=join(" ", @{$task->{description}}[1..$#{$task->{description}}]);
print dgettext("debian-tasks", $extdesc)."\n";
exit(0);
}
else {
exit(1);
}
}

# This is relatively expensive, get the full list of available tasks and
# mark them.
my @tasks=map { hide_enhancing_tasks($_) } map { task_test($_, $options{"new-install"}, 1, 0) }
grep { task_avail($_) } all_tasks();
if ($options{"list-tasks"}) {
map { $_->{_installed} = task_installed($_) } @tasks;
@tasks=getdescriptions(@tasks);
print "".($_->{_installed} ? "i" : "u")." ".$_->{task}."\t".$_->{shortdesc}."\n"
foreach order_for_display(grep { $_->{_display} } @tasks);
exit(0);
}
if ($options{"install"}) {
my $task=name_to_task($options{"install"}, @tasks);
$task->{_install} = 1 if $task;
}
if ($options{"remove"}) {
my $task=name_to_task($options{"remove"}, @tasks);
$task->{_remove} = 1 if $task;
}
if (! $options{install} && ! $options{remove}) {
interactive(\%options, @tasks);
}
# Add tasks to install
@tasks_install = grep { $_->{_install} } @tasks;
# Add tasks to remove
@tasks_remove = grep { $_->{_remove} } @tasks;

my @cmd;
if (-x "/usr/bin/debconf-apt-progress") {


Loading…
Cancel
Save