Now, with colored nodes, colored dependencies, and options handling :

#!/bin/sh

PROGNAME=$(basename $0)

NODE_COLOR=0
DEP_COLOR=0
TOP_COL=greenyellow
BOTTOM_COL=firebrick
DEP_COL=lightgrey

TOP_PKGS=""

get_fulldepends() {
       FULLDEP=
       STEP=$(pkg_info -f $1 | grep '@depend'  | cut -d':' -f3 | tr '\n' ' ')

       until [ -z "$STEP" ] ; do
               DEP=$(echo $STEP | cut -d' ' -f1)
               echo $FULLDEP | grep $DEP > /dev/null
               if [ $? -ne 0 ] ; then
                       FULLDEP="$FULLDEP $DEP"
                       STEP="$STEP $(pkg_info -f $DEP | grep
'@depend'  | cut -d':' -f3 | tr '\n' ' ')"
               fi
               STEP=$(echo $STEP | cut -s -d' ' -f2- | tr -d  '\n')
       done
       echo $FULLDEP
}

ARGS=$(getopt nDb:d:t: $*)
if [ $? -ne 0 ] ; then
       echo "$PROGNAME [-nD] [-b color] [-d color] [-t color]"
       exit 2
fi
set -- $ARGS
for i
do
       case "$i"
       in
               -n)
                       NODE_COLOR=1
                       shift;;
               -D)
                       DEP_COLOR=1
                       shift;;
               -b)
                       NODE_COLOR=1
                       BOTTOM_CO=$2; shift; shift;;
               -d)
                       DEP_COLOR=1
                       DEP_COL=$2 ; shit; shift;;
               -t)
                       NODE_COLOR=1
                       TOP_COL=$2; shift; shift;;
               --)
                       shift; break;;
       esac
done


echo "digraph pkg_dep"
echo "{"

for PKG in $(pkg_info | cut -d' ' -f1) ; do
       PKG_INFO=$(pkg_info -c $PKG | tail -n+4 | tr -s '\n')
       echo "\t\"$PKG\" [label=\"$PKG\\\n$PKG_INFO\"];"
       REQ_BY=""
       for REQ_BY in $(pkg_info -R $PKG | tail -n+4 | tr -s '\n') ; do
               echo "\t\"$REQ_BY\" -> \"$PKG\";"
       done
       if [ -z "$REQ_BY" ] ; then
               TOP_PKGS="$TOP_PKGS $PKG"
       fi
       if [ $NODE_COLOR -eq 1 ] ; then
               REQ=$(pkg_info -f $PKG | grep '@depend' | cut -d':' -f3)
               if [ -z "$REQ_BY" ] ; then
                       echo "\t\"$PKG\" [color=\"$TOP_COL\",
style=\"filled\"];"
               elif [ -z "$REQ" ] ; then
                       echo "\t\"$PKG\" [color=\"$BOTTOM_COL\",
style=\"filled\"];"
               fi
       fi
done

if [ $DEP_COLOR -eq 1 ] ; then
       for PKG in $TOP_PKGS ; do
               echo
               echo "\tsubgraph \"cluster_$PKG\""
               echo "\t{"
               echo "\t\tstyle=filled;"
               echo "\t\tcolor=$DEP_COL;"
               echo "\t\tlabel=\"all-$PKG\";"
               echo "\t\t\"$PKG\";"
               for P in $(get_fulldepends $PKG) ; do
                       echo "\t\t\"$P\";"
               done
               echo "\t}"
       done
fi

echo "}"

exit 0




2006/10/8, Bruno Carnazzi <[EMAIL PROTECTED]>:
Now, with colors :

[SNIP]


2006/10/8, Bruno Carnazzi <[EMAIL PROTECTED]>:
> First blood :
>
> [SNIP]
>
> But for my big packages set, it does not produce a beautiful graph.
> Someone know how to beautify it ?
>
> Thank you,
>
> Bruno.
>
> Attached, my generated dot file (gosh ! gdm is really a pig !) :
>
[SNIP]
>
> 2006/10/7, Matthias Kilian <[EMAIL PROTECTED]>:
> > On Sat, Oct 07, 2006 at 10:32:21PM +0400, Bruno Carnazzi wrote:
> > > Someone knows if this kind of stuff already exists ?
> >
> > I just found this one (old, untested, and after all *not* supported,
> > since it seems to directly access /var/db/pkg):
> >
> > http://vgai.de/gpkgview.sh
> >
> > Ciao,
> >         Kili

Reply via email to