From: Pierre Habouzit Date: Sun, 11 May 2008 16:31:51 +0000 (+0200) Subject: Add a --query option to update-alternatives. Closes: #336091, #441904 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b54cfc9959b66f025005a09c26309635bf6638e;p=dpkg Add a --query option to update-alternatives. Closes: #336091, #441904 * scripts/update-alternatives.pl: add a --query option that works like --display but outputs a machine parseable rfc822-like output. * man/update-alternatives.8: document that new option, and the associated format. --- diff --git a/ChangeLog b/ChangeLog index 52fb4873..699d4b10 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-05-11 Pierre Habouzit + + * scripts/update-alternatives.pl: add a --query option that works like + --display but outputs a machine parseable rfc822-like output. + * man/update-alternatives.8: document that new option, and the + associated format. + 2008-05-05 Raphael Hertzog * scripts/dpkg-gensymbols.pl: Do not accept empty parameters for diff --git a/THANKS b/THANKS index f1da8bae..f54f8654 100644 --- a/THANKS +++ b/THANKS @@ -132,6 +132,7 @@ Peter Mann Peter van Dijk Petr Cech Philippe Batailler +Pierre Habouzit Piotr Engelking Piotr Roszatycki Rakesh 'arky' Ambati diff --git a/TODO b/TODO index 7528b902..938ad346 100644 --- a/TODO +++ b/TODO @@ -106,8 +106,6 @@ lenny * Make dpkg-deb --build check for duped conffiles. (#131633) - * Make update-alternatives --display support --quiet. (#336091) - * Propagate --admindir to programs run from maintainer scritpts. (#97076) * Fix quotes? diff --git a/debian/changelog b/debian/changelog index 77542e68..c5ff7c66 100644 --- a/debian/changelog +++ b/debian/changelog @@ -10,6 +10,9 @@ dpkg (1.15.0) UNRELEASED; urgency=low * dpkg-gensymbols now refuses empty values for the the -v -P and -e parameters. + [ Pierre Habouzit ] + * Add a --query option to update-alternatives. Closes: #336091, #441904 + [ Updated dpkg translations ] * Portuguese (Miguel Figueiredo). diff --git a/man/update-alternatives.8 b/man/update-alternatives.8 index 6029c0a6..448b752b 100644 --- a/man/update-alternatives.8 +++ b/man/update-alternatives.8 @@ -283,6 +283,12 @@ what other alternatives are available (and their corresponding slave alternatives), and the highest priority alternative currently installed. .TP +\fB\-\-query\fR \fIlink\fR +Display information about the link group of which +.I link +is the master link like \-\-display does, but in a machine parseable way +(see section \fBQUERY FORMAT\fR below). +.TP \fB\-\-list\fR \fIlink\fR Display all targets of the link group. .TP @@ -339,6 +345,76 @@ The requested action was successfully performed. Problems were encountered whilst parsing the command line or performing the action. . +.SH "QUERY FORMAT" +The \fBupdate\-alternatives\fP \fI\-\-query\fP format is using an +RFC822-like flat format. It's made of \fIn\fP + 1 blocks where \fIn\fP is +the number of alternatives available in the queried link group. The first +block contains the following fields: +.TP +.BR Link: " " +The generic name of the alternative. +.TP +.BR Status: " " +The status of the alternative (\fBauto\fR or \fBmanual\fR). +.TP +.BR Best: " " +The path of the best alternative for this link group. Not present if +there is no alternatives available. +.TP +.BR Value: " " +The path of the currently selected alternative. It can also take the magic +values \fBnone\fR or \fBerror\fR. The former is used if the link doesn't +exist, and the latter in case of error. +.TP +.BR Error: " " +When \fBValue\fR is \fBerror\fR, this field is present and contains a human readable +string explaining the error. +. +.TP +The other blocks describe the available alternatives in the queried link group: +.TP +.BR Alternative: " " +Path to this block's alternative. +.TP +.BR Priority: " " +Value of the priority of this alternative. +.TP +.BR Slaves: " " +When this header is present, the \fBnext\fR lines hold all slave alternatives +associated to the master link of the alternative. There is one slave per +line. Each line contains one space, the generic name of the slave +alternative, another space, and the path to the slave alternative. +. +.TP +.BR Example +.nf +$ update\-alternatives \-\-query editor +Link: editor +Status: auto +Best: /usr/bin/vim.gtk +Value: /usr/bin/vim.gtk + +Alternative: /bin/ed +Priority: \-100 +Slaves: + editor.1.gz /usr/share/man/man1/ed.1.gz + +Alternative: /usr/bin/vim.gtk +Priority: 50 +Slaves: + editor.1.gz /usr/share/man/man1/vim.1.gz + editor.ru.1.gz /usr/share/man/ru/man1/vim.1.gz + editor.pl.ISO8859-2.1.gz /usr/share/man/pl.ISO8859-2/man1/vim.1.gz + editor.it.ISO8859-1.1.gz /usr/share/man/it.ISO8859-1/man1/vim.1.gz + editor.pl.UTF-8.1.gz /usr/share/man/pl.UTF-8/man1/vim.1.gz + editor.it.1.gz /usr/share/man/it/man1/vim.1.gz + editor.fr.UTF-8.1.gz /usr/share/man/fr.UTF-8/man1/vim.1.gz + editor.fr.1.gz /usr/share/man/fr/man1/vim.1.gz + editor.it.UTF-8.1.gz /usr/share/man/it.UTF-8/man1/vim.1.gz + editor.pl.1.gz /usr/share/man/pl/man1/vim.1.gz + editor.fr.ISO8859-1.1.gz /usr/share/man/fr.ISO8859-1/man1/vim.1.gz +.fi +. .SH DIAGNOSTICS .B update\-alternatives chatters incessantly about its activities on its standard output channel. diff --git a/scripts/update-alternatives.pl b/scripts/update-alternatives.pl index 8b9b193e..2ff1069e 100755 --- a/scripts/update-alternatives.pl +++ b/scripts/update-alternatives.pl @@ -17,7 +17,7 @@ $admindir = $admindir . '/alternatives'; my $verbosemode = 0; -my $action = ''; # Action to perform (display / install / remove / display / auto / config) +my $action = ''; # Action to perform (display / query / install / remove / auto / config) my $mode = 'auto'; # Update mode for alternative (manual / auto) my $state; # State of alternative: # expected: alternative with highest priority is the active alternative @@ -78,6 +78,7 @@ Commands: --remove-all remove group from the alternatives system. --auto switch the master link to automatic mode. --display display information about the group. + --query machine parseable version of --display . --list display all targets of the group. --config show alternatives for the group and ask the user to select which one to use. @@ -212,6 +213,38 @@ sub display_link_group } } +sub query_link_group +{ + pr(sprintf("Link: %s", $name)); + pr(sprintf("Status: %s", $mode)); + if ($best ne '') { + pr(sprintf("Best: %s", $best)); + } + $linkname = readlink("$altdir/$name"); + + if (defined($linkname)) { + pr(sprintf("Value: %s", $linkname)); + } elsif ($! == ENOENT) { + pr("Value: none"); + } else { + pr("Value: error"); + pr(sprintf("Error: %s", $!)); + } + + for (my $i = 0; $i <= $#versions; $i++) { + pr(""); + pr(sprintf("Alternative: %s", $versions[$i])); + pr(sprintf("Priority: %s", $priorities[$i])); + next unless ($#slavenames >= 0); + pr("Slaves:"); + for (my $j = 0; $j <= $#slavenames; $j++) { + my $tspath = $slavepath{$i, $j}; + next unless length($tspath); + pr(sprintf(" %s %s", $slavenames[$j], $tspath)); + } + } +} + sub list_link_group { for (my $i = 0; $i <= $#versions; $i++) { @@ -314,7 +347,7 @@ while (@ARGV) { @ARGV >= 2 || &badusage(sprintf(_g("--%s needs "), $1)); ($name,$apath,@ARGV) = @ARGV; $action = $1; - } elsif (m/^--(display|auto|config|list|remove-all)$/) { + } elsif (m/^--(display|query|auto|config|list|remove-all)$/) { check_many_actions(); @ARGV || &badusage(sprintf(_g("--%s needs "), $1)); $action = $1; @@ -345,7 +378,7 @@ defined($alink) && $aslavelinkcount{$alink} && badusage(sprintf(_g("link %s is both primary and slave"), $alink)); $action || - badusage(_g("need --display, --config, --set, --install, --remove, --all, --remove-all or --auto")); + badusage(_g("need --display, --query, --config, --set, --install, --remove, --all, --remove-all or --auto")); $action eq 'install' || !%aslavelink || badusage(_g("--slave only allowed with --install")); @@ -371,6 +404,12 @@ if ($action eq 'display') { exit 0; } +if ($action eq 'query') { + find_best_version(); + query_link_group(); + exit 0; +} + if ($action eq 'list') { list_link_group(); exit 0;