+2008-05-11 Pierre Habouzit <madcoder@debian.org>
+
+ * 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 <hertzog@debian.org>
* scripts/dpkg-gensymbols.pl: Do not accept empty parameters for
Peter van Dijk <peter@dataloss.nl>
Petr Cech <cech@atrey.karlin.mff.cuni.cz>
Philippe Batailler <pbatailler@teaser.fr>
+Pierre Habouzit <madcoder@debian.org>
Piotr Engelking <inkerman42@gmail.com>
Piotr Roszatycki <dexter@fnet.pl>
Rakesh 'arky' Ambati <rakesh_ambati@yahoo.com>
* 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? <http://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html>
* 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).
(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
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: " <link>"
+The generic name of the alternative.
+.TP
+.BR Status: " <status>"
+The status of the alternative (\fBauto\fR or \fBmanual\fR).
+.TP
+.BR Best: " <best choice>"
+The path of the best alternative for this link group. Not present if
+there is no alternatives available.
+.TP
+.BR Value: " <currently selected alternative> "
+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: " <error details>"
+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 of this alternative>"
+Path to this block's alternative.
+.TP
+.BR Priority: " <priority value>"
+Value of the priority of this alternative.
+.TP
+.BR Slaves: " <list of 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.
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
--remove-all <name> remove <name> group from the alternatives system.
--auto <name> switch the master link <name> to automatic mode.
--display <name> display information about the <name> group.
+ --query <name> machine parseable version of --display <name>.
--list <name> display all targets of the <name> group.
--config <name> show alternatives for the <name> group and ask the
user to select which one to use.
}
}
+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++) {
@ARGV >= 2 || &badusage(sprintf(_g("--%s needs <name> <path>"), $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 <name>"), $1));
$action = $1;
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"));
exit 0;
}
+if ($action eq 'query') {
+ find_best_version();
+ query_link_group();
+ exit 0;
+}
+
if ($action eq 'list') {
list_link_group();
exit 0;