The following commit has been merged in the master branch:
commit 50652b69c1077cc3a7d728ecabe366fce1c21645
Author: Raphael Hertzog <[email protected]>
Date: Sun Feb 22 17:36:16 2009 +0100
update-alternatives: new option --set-selections
The option --set-selections is the counterpart of --get-selections,
it reads configuration on standard input and reconfigures alternatives
accordingly.
diff --git a/ChangeLog b/ChangeLog
index d31e292..c902f86 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2009-02-22 Raphael Hertzog <[email protected]>
+ * scripts/update-alternatives.pl: Implement --set-selections.
+ It's the the counterpart of --get-selections, it reads
+ configuration on standard input and reconfigures alternatives
+ accordingly.
+ * man/update-alternatives.8: Document this option.
+ * scripts/t/900_update_alternatives.t: Add corresponding tests in
+ the test suite.
+
+2009-02-22 Raphael Hertzog <[email protected]>
+
* scripts/update-alternatives.pl: Implement --get-selections.
The new option lists all master alternatives and their status in a
format simple to parse.
diff --git a/debian/changelog b/debian/changelog
index e68c20e..a2422fa 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -166,6 +166,8 @@ dpkg (1.15.0) UNRELEASED; urgency=low
- new option --get-selections to export the configuration of all
alternatives. It's a simple way to discover the name of all available
alternatives. Closes: #273406, #392429
+ - new option --set-selections to reconfigure a set of alternatives in
+ a single command.
[ Pierre Habouzit ]
* Add a --query option to update-alternatives. Closes: #336091, #441904
diff --git a/man/update-alternatives.8 b/man/update-alternatives.8
index 3086305..4b8a4b9 100644
--- a/man/update-alternatives.8
+++ b/man/update-alternatives.8
@@ -295,6 +295,11 @@ one is the status (either "auto" or "manual"), and the
last one contains
the current choice in the alternative (beware: it's a filename and thus
might contain spaces).
.TP
+\fB\-\-set\-selections\fR
+Read configuration of alternatives on standard input in the format
+generated by \fBupdate-alternatives \-\-get\-selections\fR and reconfigure
+them accordingly.
+.TP
\fB\-\-query\fR \fIname\fR
Display information about the link group
like \-\-display does, but in a machine parseable way
diff --git a/scripts/t/900_update_alternatives.t
b/scripts/t/900_update_alternatives.t
index 00ca86f..b9d2908 100644
--- a/scripts/t/900_update_alternatives.t
+++ b/scripts/t/900_update_alternatives.t
@@ -52,8 +52,8 @@ my @choices = (
},
);
my $nb_slaves = 2;
-plan tests => (4 * ($nb_slaves + 1) + 2) * 21 # number of check_choices
- + 54; # rest
+plan tests => (4 * ($nb_slaves + 1) + 2) * 23 # number of check_choices
+ + 56; # rest
sub cleanup {
system("rm -rf $srcdir/t.tmp/ua && mkdir -p $admindir && mkdir -p
$altdir");
@@ -110,7 +110,6 @@ sub config_choice {
$opts{to_string} = \$output;
my @params = ("--config", $main_name);
call_ua(\...@params, %opts);
- #print STDERR "Output of @params for choice $input $output\n";
}
sub get_slaves_status {
@@ -195,6 +194,16 @@ install_choice(2); # 2 is lower prio, stays at 1
check_choice(1, "auto", "initial install 2");
install_choice(0); # 0 is higher priority
check_choice(0, "auto", "initial install 3");
+# manual change with --set-selections
+my $input = "doesntexist auto /bin/date\ngeneric-test manual /bin/false\n";
+my $output = "";
+call_ua(["--set-selections"], from_string => \$input,
+ to_string => \$output);
+check_choice(1, "manual", "manual update with --set-selections");
+$input = "generic-test auto /bin/true\n";
+call_ua(["--set-selections"], from_string => \$input,
+ to_string => \$output);
+check_choice(0, "auto", "auto update with --set-selections");
# manual change with set
set_choice(2);
check_choice(2, "manual", "manual update with --set"); # test #388313
diff --git a/scripts/update-alternatives.pl b/scripts/update-alternatives.pl
index 65726d5..18c147d 100755
--- a/scripts/update-alternatives.pl
+++ b/scripts/update-alternatives.pl
@@ -25,6 +25,7 @@ my $inst_alt; # Alternative to install
my $fileset; # Set of files to install in the alternative
my $path; # Path of alternative we are offering
my $verbosemode = 0;
+my @pass_opts;
$| = 1;
@@ -46,8 +47,10 @@ while (@ARGV) {
exit(0);
} elsif (m/^--verbose$/) {
$verbosemode= +1;
+ push @pass_opts, $_;
} elsif (m/^--quiet$/) {
$verbosemode= -1;
+ push @pass_opts, $_;
} elsif (m/^--install$/) {
set_action("install");
@ARGV >= 4 || badusage(_g("--install needs <link> <name> <path>
<priority>"));
@@ -70,7 +73,7 @@ while (@ARGV) {
set_action($1);
@ARGV || badusage(_g("--%s needs <name>"), $1);
$alternative = Alternative->new(shift(@ARGV));
- } elsif (m/^--(all|get-selections)$/) {
+ } elsif (m/^--(all|get-selections|set-selections)$/) {
set_action($1);
} elsif (m/^--slave$/) {
badusage(_g("--slave only allowed with --install"))
@@ -95,18 +98,22 @@ while (@ARGV) {
} elsif (m/^--altdir$/) {
@ARGV || badusage(_g("--%s needs a <directory> argument"), "altdir");
$altdir = shift @ARGV;
+ push @pass_opts, $_, $altdir;
} elsif (m/^--admindir$/) {
@ARGV || badusage(_g("--%s needs a <directory> argument"), "admindir");
$admdir = shift @ARGV;
+ push @pass_opts, $_, $admdir;
} elsif (m/^--skip-auto$/) {
$skip_auto = 1;
+ push @pass_opts, $_;
} else {
badusage(_g("unknown option \`%s'"), $_);
}
}
badusage(_g("need --display, --query, --list, --get-selections, --config," .
- "--set, --install, --remove, --all, --remove-all or --auto"))
+ "--set, --set-selections, --install, --remove, --all, " .
+ "--remove-all or --auto"))
unless $action;
# Load infos about all alternatives to be able to check for mistakes
@@ -175,8 +182,40 @@ if ($action eq 'all') {
printf "%-30s %-8s %s\n", $alt_name, $obj->status(), $obj->current()
|| "";
}
exit 0;
+} elsif ($action eq 'set-selections') {
+ log_msg("run with @COPY_ARGV");
+ my $line;
+ while (defined($line = <STDIN>)) {
+ chomp($line);
+ my ($alt_name, $status, $choice) = split(/\s+/, $line, 3);
+ if (exists $ALL{objects}{$alt_name}) {
+ my $obj = $ALL{objects}{$alt_name};
+ if ($status eq "auto") {
+ pr("[$progname --set-selections] " . _g("Call %s."),
+ "$0 --auto $alt_name");
+ system($0, @pass_opts, "--auto", $alt_name);
+ exit $? if $?;
+ } else {
+ if ($obj->has_choice($choice)) {
+ pr("[$progname --set-selections] " . _g("Call %s."),
+ "$0 --set $alt_name $choice");
+ system($0, @pass_opts, "--set", $alt_name, $choice);
+ exit $? if $?;
+ } else {
+ pr("[$progname --set-selections] " . _g("Alternative %s" .
+ " unchanged because choice %s is not available."),
+ $alt_name, $choice);
+ }
+ }
+ } else {
+ pr("[$progname --set-selections] " . _g("Skip unknown alternative
%s."),
+ $alt_name);
+ }
+ }
+ exit 0;
}
+
# Load the alternative info, stop on failure except for --install
if (not $alternative->load("$admdir/" . $alternative->name())
and $action ne "install")
@@ -451,7 +490,7 @@ sub get_all_alternatives {
sub config_all {
foreach my $name (get_all_alternatives()) {
- system "$0 $skip --config $name";
+ system($0, @pass_opts, "--config", $name);
exit $? if $?;
print "\n";
}
--
dpkg's main repository
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]