You are not logged in.

#1 2009-06-15 17:02:02

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,403
Website

wanted: script to list uninstalled optdepends and packages that need t

I had a thought today that a script to list package that are optdepends but not installed could be quite useful...  I have not written one, but thought it would be good for pacman-contrib if someone wanted to contribute.

Example output:

tk - optional for:
   ruby - for Ruby/TK
   python - for IDLE, pynche and modulator
fakeroot - optional for:
   pacman - for makepkg usage as normal user

So get script writing!  Preferably in bash or perl (which the current pacman-contrib scripts use).

Offline

#2 2009-06-15 23:38:59

juster
Forum Fellow
Registered: 2008-10-07
Posts: 195

Re: wanted: script to list uninstalled optdepends and packages that need t

I cheated and used my perl ALPM module.  I think the logic is sound, though, and you can replace the module calls with backticking pacman (preferably functions wrapping them).  I planned to but ran out of time.

#!/usr/bin/perl

use warnings;
use strict;

use ALPM ( dbpath => '/var/lib/pacman/' );

my %reverse_depends;

my $db = ALPM->register_db;
OPT_SEARCH:
for my $pkg ( @{$db->get_pkg_cache} ) {
    my $pkg_optdeps = $pkg->get_optdepends;
    next OPT_SEARCH unless @$pkg_optdeps;

    my $depender = $pkg->get_name;
    my %reason_for = map {
        /\A([^:]*):\s*(.*)/ ? ($1 => $2) : ($_ => '')
    } @$pkg_optdeps;

    DEP_LOOP:
    for my $dependee ( keys %reason_for ) {
        next DEP_LOOP if $db->get_pkg($dependee); #ignore installed
        $reverse_depends{$dependee}->{$depender} = $reason_for{$dependee};
    }
}

for my $opt_dep ( sort keys %reverse_depends ) {
    print "$opt_dep\n";
    my $reason_of = $reverse_depends{$opt_dep};
    for my $depender ( sort keys %$reason_of ) {
        my $reason = $reason_of->{$depender};
        print "    $depender",
            ( $reason ? ": $reason\n" : "\n" );
    }
}

Offline

#3 2009-06-16 00:06:35

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: wanted: script to list uninstalled optdepends and packages that need t

I posted a script to pacman-dev before I saw this thread:
http://www.archlinux.org/pipermail/pacm … 08768.html


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#4 2009-06-16 00:33:27

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,403
Website

Re: wanted: script to list uninstalled optdepends and packages that need t

I decided to advertise far and wide for someone to write this... sorry for the overlap.    Although there are bits of both that I like so a combination of the two might be a good thing (Xyne's does not use an external perl module and does stuff with provides, juster's looks directly at the pacman db rather than using -Qi output).

But these have been useful for me already.  I have a couple of packages the are optdepends for multiple packages, so they become more attractive to install.

Offline

#5 2009-06-16 03:45:28

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: wanted: script to list uninstalled optdepends and packages that need t

Juster's version using an XS module to interact with alpm is obviously a better solution in the long run. I should have implemented that myself but my complete lack of experience with C or any other low-level language has kept me away from such things. I'm actually reading through the XS documentation for Perl right now after having discovered Juster's alpm module (and getting sidetracked into the equivalent for Python, along with a C tutorial... I'm prone to chaining).

Somehow related: http://xkcd.com/409/


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

Board footer

Powered by FluxBB