From owner-freebsd-questions@FreeBSD.ORG Sun Mar 9 11:05:40 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 0F14B209 for ; Sun, 9 Mar 2014 11:05:40 +0000 (UTC) Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4CDE6C4C for ; Sun, 9 Mar 2014 11:05:38 +0000 (UTC) Received: from nb981.math (p57AEC7E0.dip0.t-ipconnect.de [87.174.199.224]) by mrelayeu.kundenserver.de (node=mreue006) with ESMTP (Nemesis) id 0LenO7-1WxuUd3H2N-00qleO; Sun, 09 Mar 2014 12:05:17 +0100 Message-ID: <531C4AEE.6030007@janh.de> Date: Sun, 09 Mar 2014 12:05:18 +0100 From: Jan Henrik Sylvester User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: "R. Scott Evans" Subject: Re: pkg equivalent of "pkg_info -R" References: <53186ABC.5060601@netfence.it> <20140306184030.078a99cedac859b5c5b83e22@embarqmail.com> <53196D17.8000300@FreeBSD.org> <5319F0B7.3030200@netfence.it> <531A0210.3070705@rsle.net> In-Reply-To: <531A0210.3070705@rsle.net> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:1AbgtYS4jkHMzvlDX7rygf4GCNE+6PqIRxo2d0gODY2 xO+bhPeJmjONVNgBa2nx6sNXmmuD2iYLuTXCC2WQkd2g82Yczt 62tpJvFI7auL11uiI8CJpLV04x0Rn/Y1jcHCqw4ilhuOnXm/Pb L9UHhC1q/o77AtRHSarHnKsrw9w52L9M72eb4WJ2/XZrj9IlFO uNYTRSie+UFNRgeYEi7hHQwaXgwrgSLLGZTgYCL+G6ctvGDam9 O6pdPFNynIK+zI99AsXZ2Qj2ZzAr/nSPpZkjAHNKeVy3ju10Pp MDHmmP4P4DeSqW/eb9gfUKGHNrnyId8JQFQIFln7URyXqtDFg= = Cc: questions-list freebsd X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 09 Mar 2014 11:05:40 -0000 On 03/07/2014 18:29, R. Scott Evans wrote: >> On 03/07/14 07:54, Matthew Seaman wrote: >> >>> Yes, being able to generate the entire dependency tree would be a >>> desirable option. > Okay, you got a python solution but here's my bourne shell version (I > dislike python :-) Your script was a little bit slow for my taste, since it does many external calls. As I needed a script for dependencies myself (not reverse, which can be printed by pkg delete -Rn), I rewrote it using - as few calls to pkg as possible, only as many as the depth of recursion, - origins instead of names and versions, - pkg query instead of pkg info, - and no other external calls. For gnutls on my system, your script needs 5s and mine .2s, while pkg delete -Rn needs .07s, which is probably as fast as possible. The next person should really patch pkg query itself. Cheers, Jan Henrik #!/bin/sh [ "$1" = "-h" ] && { echo "\ NAME: $0 -- pkg query recursive dependencies or reverse dependencies SYNOPSIS: $0 [-r] [-gix] OPTIONS: -r for reverse dependencies [-gix] is passed to pkg query\ " ; exit 0 ; } [ "$1" = "-r" ] && { DEP=r ; shift ; } || DEP=d [ "$1" != "${1#-}" ] && { OPTIONS=$1 ; shift ; } || OPTIONS= ## using %o temporarily is significantly fast than %n-%v directly ## DEP_COMMAND="pkg query $OPTIONS %${DEP}o" S=' ' LIST="$S$($DEP_COMMAND "$@")$S" NEW=$LIST while [ ${#NEW} -gt 2 ] do TRY=$NEW NEW=$S for TRY in $($DEP_COMMAND $TRY) do if [ "$LIST" = "${LIST%%$S$TRY$S*}" ] then NEW="$NEW$TRY$S" LIST="$LIST$TRY$S" fi done done ## for origins, use instead: printf %s "${LIST#$S}" ## [ ${#LIST} -gt 2 ] && pkg query %n-%v $LIST