You are not logged in.

#1 2005-02-25 03:14:10

skoal
Member
From: Frequent Flyer Underworld
Registered: 2004-03-23
Posts: 612
Website

Pacman Dependency Tree

I wrote this little script since I wanted a more visual representation of my pacman dependencies.  Also, I noticed a few threads recently about package dependencies in general.  This might help some with those questions.  If nothing else, it at least helped me answer my orphans question...

Just copy this to a file, as in `pacdep.sh`, make it executable with `chmod ug+x pacdep.sh`, and you'll get yourself a "pretty" tree diagram of your package dependencies.  The package is the root and at the top.

USAGE: ./pacdep.sh <package>

#!/bin/sh
# Pacman Dependency Tree
# does NOT handle group names -> unexpected results.
# Package names using aliases, like x-server, should work.
# Breaks on circular dependencies -> you better hit ctrl-c.

progname=`basename $0`
pacexec=`which pacman`
leafnull='None'
branch=""
vbranch="|   "
vprune="    "
hbranch="+---"

_showdep () {

    # Try to use specific pkg req
    if $pacexec -Qi $1 &> /dev/null ; then
         # Grab deps list|from "Depends"|Remove Tag | specific version req's.
        deplist=`$pacexec -Qi $1|grep Depends|sed 's/^.*: |>[^ ]*//g;s/ $//'`
    else # Oops! Failed on alias, try this...
        deplist=`$pacexec -Qs $1 | sed '1!d;s/(^.*/)(.*)( .*$)/2/'`
    fi

    [ "x$deplist" = "x$leafnull" ] && return

    while [ -n "$deplist" ]
    do
        set -- $deplist && echo "$branch$hbranch$1"
        if [ $# -gt 1 ] ; then
            branch=${branch}$vbranch
        else
            branch=${branch}$vprune
        fi

        _showdep $1

        deplist=${*:2}
        branch=${branch:0:${#branch}-${#vprune}}
    done
}

branch=$vprune

for pkg in `$pacexec -Q $1 | sed 's/ .*//'`
do
    echo $pkg
    _showdep $pkg
done

unset _showdep && set --
exit 0

Just a few notes:

1. It breaks on circular dependencies.  I had a problem with it on the "cups" package. 

cups -> gcc ghostscript libjpeg [...]
ghostscript -> gimp-print glib xfree86
gimp-print -> cups readline

* You see the problem...

2. Pass a specific name on the command line, like `pacdep.sh sysvinit` and it will give you a tree representation of all the dependencies needed to build it.

3. If you don't pass an argument, it will display all the package trees, until it breaks on "item 1" above.

4. Add color if you want.  I left out many options to make it smaller and easily piped to a text file for reading.

5. If you pass a wildcard name, you will get unexpected results.  Exact package names help, but the version info is not needed, just like a regular `pacman -Q <package>`.

6. Feel free to make any changes, and post back if you have any additions/changes you would like to it.  I'd like to add a few things myself but don't have the time, like group and wildcard parameters, color option, and handling circular dependencies.

Offline

#2 2005-02-25 09:19:51

Cam
Member
From: Brisbane, Aus
Registered: 2004-12-21
Posts: 658
Website

Re: Pacman Dependency Tree

Wow. Some of the simplest apps have a lot of dependencies... or I just found another loop tongue

Offline

#3 2005-02-25 09:32:26

Spider.007
Member
Registered: 2004-06-20
Posts: 1,175

Re: Pacman Dependency Tree

I was working on a similar script; but mine was a bit bigger.. I will try this one and see if I can add some things smile

Offline

#4 2005-02-25 10:25:12

dp
Member
From: Zürich, Switzerland
Registered: 2003-05-27
Posts: 3,378
Website

Re: Pacman Dependency Tree

very nice script!

[damir@Asteraceae ~]$ ./deptree.sh vips
vips
    +---fftw
    |   +---glibc
    +---glib2
    |   +---pkgconfig
    |       +---glibc
    +---imagemagick
    |   +---bzip2
    |   |   +---bash
    |   |   |   +---glibc
    |   |   |   +---readline
    |   |   |       +---glibc
    |   |   |       +---ncurses
    |   |   |           +---glibc
    |   |   +---glibc
    |   +---libtiff
    |   |   +---gcc
    |   |   |   +---binutils
    |   |   |   |   +---glibc
    |   |   |   +---glibc
    |   |   +---libjpeg
    |   |   |   +---glibc
    |   |   +---zlib
    |   |       +---glibc
    |   +---libtool
    |   |   +---bash
    |   |       +---glibc
    |   |       +---readline
...

i see optimisation potential:

- instead of running pacman -Q.. accessing the db files directly (i don't know yet how, to be faster)

- caching already known subtrees (in the example above, after finding out the subtree for "bash" you can re-use it for the second occurence of "bash" and save a lot of time)

cool nice-to-have features:

- port to a faster scripting lang (maybe i will do that, if i find some time)

- export to svg, ...

- better visualisation: e.g. using infovis ( http://ivtk.sourceforge.net/ )


The impossible missions are the only ones which succeed.

Offline

#5 2005-02-25 23:31:08

skoal
Member
From: Frequent Flyer Underworld
Registered: 2004-03-23
Posts: 612
Website

Re: Pacman Dependency Tree

dp wrote:

- instead of running pacman -Q.. accessing the db files directly (i don't know yet how, to be faster)

Where are the "db" files, dp?  I keep hearing "db" when people talk aobut pacman, but I don't see a backend used anywhere.  The only thing I can figure are the various keys used in `/var/lib/pacman/local/<pkg>`, generated by pacman's internal "db".  Is that the db you're talking about?

A hash table would work nicely in pruning redundant trees.  Any other dependency in the tree using it, would just print that dependency, stop at printing the rest of that tree, and move back up.  This script is pretty dumb in that it uses recursion, but recursion is easier for me to understand and implement.

Cam, you'll know a circular loop when you see one, like the cups package.  I think what you're seeing is just multiple m-way dependency subtrees stacked under eachother, which could be pruned.

Offline

#6 2005-02-26 18:14:54

Spider.007
Member
Registered: 2004-06-20
Posts: 1,175

Re: Pacman Dependency Tree

I have written a new script based on the one posted by skoal smile

It's biggest feature is that it caches the dependencies; and is better seperated into functions; allowing for easier updating. I will add loop detection in it too smile It might be useful to distribute with the default arch-distro too! Do you mind if I post it in it's own topic?

pacmanDeps - recursive package dependency viewer

Offline

#7 2005-02-27 00:43:22

dp
Member
From: Zürich, Switzerland
Registered: 2003-05-27
Posts: 3,378
Website

Re: Pacman Dependency Tree

skoal wrote:
dp wrote:

- instead of running pacman -Q.. accessing the db files directly (i don't know yet how, to be faster)

Where are the "db" files, dp?  I keep hearing "db" when people talk aobut pacman, but I don't see a backend used anywhere.  The only thing I can figure are the various keys used in `/var/lib/pacman/local/<pkg>`, generated by pacman's internal "db".  Is that the db you're talking about?

yes ... i wish it would be in a more modern format (sqlite or something like tihs)


The impossible missions are the only ones which succeed.

Offline

#8 2005-02-27 02:34:03

rasat
Forum Fellow
From: Finland, working in Romania
Registered: 2002-12-27
Posts: 2,293
Website

Re: Pacman Dependency Tree

NIce!
I have asked Tigger to add your script in his Pacmenu.
http://bbs.archlinux.org/viewtopic.php?p=69955


Markku

Offline

#9 2005-02-27 15:10:37

skoal
Member
From: Frequent Flyer Underworld
Registered: 2004-03-23
Posts: 612
Website

Re: Pacman Dependency Tree

After hitting those circular dependencies, I was going to rewrite this in perl, so I could take advantage of it's builtin hashing.  Plus, if I ever got some time, I was going to add some gtk-perl backend stuff to it.  Feel free to rip, roast, or use this thing as you like...I just made it primarily to help me prune my system a bit.

Offline

#10 2005-02-27 18:29:32

dp
Member
From: Zürich, Switzerland
Registered: 2003-05-27
Posts: 3,378
Website

Re: Pacman Dependency Tree

skoal wrote:

After hitting those circular dependencies, I was going to rewrite this in perl, so I could take advantage of it's builtin hashing.  Plus, if I ever got some time, I was going to add some gtk-perl backend stuff to it.  Feel free to rip, roast, or use this thing as you like...I just made it primarily to help me prune my system a bit.

it will be much faster to parse the data here:
/var/lib/pacman/local/<pkg>
instead of running pacman Q? ... at least on my system it is (>1100 pkgs installed)... but getting data from there with bash/awk is not that failsave and can cause trouble (i messed some time ago with it but run into problems like: if same pkg exists in 3 repos in different versions or if pkg exists in different versions and virtual provides exist)

on the next holidays or on the next long weekend i will try to make a pacdb2sqlite script or something similar


The impossible missions are the only ones which succeed.

Offline

#11 2005-02-28 02:49:27

skoal
Member
From: Frequent Flyer Underworld
Registered: 2004-03-23
Posts: 612
Website

Re: Pacman Dependency Tree

dp wrote:

[...]it will be much faster to parse the data here:
/var/lib/pacman/local/<pkg>
instead of running pacman Q? [...]

You're probably right, dp.  I just figured using the pacman as a frontend would be more reliable, since the end result of any developer changes would show up there, and I barely peeked under the covers of the pacman code myself.  I thought about using the keys in `/var/lib/...`, but I didn't know that I could trust the "db" implementation would remain the same.  My "sed"(s)/"pacman -q" are probably no more reliable for that matter.  In the end, it was "eenie...meenie...minie...mo".  "mo" being what I perceived as reliability vs. speed, if either could be computed accurately anyway.

Either way, I look forward to seeing the efforts you talented programmers apply to a dependency tree, in any shape or form.  It looks like some have already started that anyway, so I'm glad others find it ueseful, as I did for my specific need.

Offline

#12 2005-02-28 08:44:05

Spider.007
Member
Registered: 2004-06-20
Posts: 1,175

Re: Pacman Dependency Tree

I have posted some stats in the other topic that show a nice performance boost when parsing the dependencies yourself. pacman costs 0.040 seconds; while parsing it yourself costs  something like 0.010 seconds. If you fix the deploops in this script we can run both scripts to see what difference the caching gives

Offline

Board footer

Powered by FluxBB