I made a modification to resolve a minor inconvenience I noticed.
Trying pkg_dig with python-tkinter was giving me this result:

[EMAIL PROTECTED] msid $ pkg_dig python-tkinter

*- Package matched: python-tkinter-2.4.3p0
|- Dependencies: tcl-8.4.7p1 python-2.4.3p0 tk-8.4.7
|- Required by: none
|- You may also delete: tk-8.4.7

[EMAIL PROTECTED] msid $ 

The problem here is that tcl-8.4.7p1 can be deleted as well since it is
required only by tk-8.4.7 which, as shown above, can be safely removed.
So, I made it check if any dependency depends on another as well. The
result of this change:

[EMAIL PROTECTED] msid $ pkg_dig python-tkinter

*- Package matched: python-tkinter-2.4.3p0
|- Dependencies: tcl-8.4.7p1 python-2.4.3p0 tk-8.4.7
|- Required by: none
|- You may also delete: tcl-8.4.7p1 tk-8.4.7

[EMAIL PROTECTED] msid $ 

I forgot to mention from the beginning that the script is totally
harmless. It does not change anything on your system. It serves only for
informational purposes. Finally, refetch, test, send feedback.

http://black.daemons.gr/msid/scripts/pkg_dig

-- 
Sideris Michael
http://black.daemons.gr/msid/
#!/bin/sh

# Copyright (c) 2006, Sideris Michael
# All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#   * Redistributions of source code must retain the above copyright
#     notice, this list of conditions and the following disclaimer.
#   * Redistributions in binary form must reproduce the above copyright
#     notice, this list of conditions and the following disclaimer in the
#     documentation and/or other materials provided with the
#     distribution.
#   * Neither the name of the author nor the names of its
#     contributors may be used to endorse or promote products derived
#     from this software without specific prior written permission.
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

if [ $# -eq 0 ]
then
        echo Usage: `echo $0 |sed 's/^\.\///'` [pkg_name ...]
        exit 0
fi

echo

for arg in $*
do
        if [ true ]
        then
                pkgdb=/var/db/pkg
                pkgname=
                search=
                counter=0

                if [ ! -d $pkgdb ]
                then
                        exit 1
                fi

                cd $pkgdb

                if [ -d $arg ]
                then
                        pkgname=$arg
                        counter=1
                else
                        search=`find . -maxdepth 1 -type d -name "$arg*" | sort 
| sed 's/^\.\///'`

                        for x in $search
                        do
                                if [ $arg == `echo $x | sed -e 's/^\.\///' -e 
's/-[0-9].*//'` ]
                                then
                                        counter=`expr $counter+1 |bc`
                                        pkgname=${pkgname}\ $x
                                fi
                        done
                fi

                if [ "$counter" -eq 0 ]
                then
                        echo "*" No package found: $arg
                elif [ "$counter" -gt 1 ]
                then
                        echo \* Ambiguous: $arg could be `echo $pkgname |sed 
's/ /\ or\ /'`
                else
                        echo \*\- Package matched: $pkgname

                        if [ -f $pkgname/+REQUIRING ]
                        then
                                deps=`cat $pkgname/+REQUIRING`
                                echo \|- Dependencies: $deps
                        else
                                deps=
                                echo \|- Dependencies: none
                        fi

                        if [ -f $pkgname/+REQUIRED_BY ]
                        then
                                required_by=`cat $pkgname/+REQUIRED_BY`
                                echo \|- Required by: $required_by
                        else
                                required_by=
                                echo \|- Required by: none
                        fi

                        if [ "$deps" ]
                        then
                                for x in $deps
                                do
                                        if [ -f $x/+REQUIRED_BY ]
                                        then
                                                tmp=`echo $deps |sed 's/ / -e 
/g'`
                                                if [ `grep -cv -e $pkgname -e 
$tmp $x/+REQUIRED_BY` -gt 0 ]
                                                then
                                                        deps=`echo "$deps" |sed 
-e 's/'$x'//' -e '/^ *$/d'`
                                                fi
                                        fi
                                done
                        fi

                        if [ "$deps" ]
                        then
                                echo \|- You may also delete: $deps
                        else
                                echo \|- You may also delete: none
                        fi
                fi
        fi

        echo
done

Reply via email to