[pacman-dev] [PATCH] contrib/pactree: generate reverse dependency trees

Allan McRae allan at archlinux.org
Tue Apr 20 08:25:12 CEST 2010


From: Christophe Chapuis <chris.chapuis at gmail.com>

Add an option to show the tree of packages which depend on a given
package

Signed-off-by: Allan McRae <allan at archlinux.org>
---

Just a git diff from Christophe's original patch.  I adjusted the patch
slightly so that the original was the first path in the if/else
statements.  Also bumped pkgver a larger version.

 contrib/pactree |   31 ++++++++++++++++++++++++++-----
 1 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/contrib/pactree b/contrib/pactree
index df53671..73bece3 100755
--- a/contrib/pactree
+++ b/contrib/pactree
@@ -41,7 +41,7 @@ arrow1_color="chocolate4"     #color of the normal arrow
 arrow2_color="grey"           #color of the "provided by" headless arrow
 
 readonly prog_name="pactree"
-readonly prog_ver="0.2"
+readonly prog_ver="0.3"
 
 _usage(){
 	echo "This program generates the dependency tree of an installed package"
@@ -52,13 +52,14 @@ _usage(){
 	echo "  -d, --depth INT            Limit the shown dependencies depth"
 	echo "  -g, --graph                Use graphviz to make an image of the tree"
 	echo "  -l, --linear               Enable linear output"
+	echo "  -r, --reversed             Show reversed dependancies"
 	echo "  -s, --silent               Shh, let me hear those errors!"
 	echo "  -u, --unique               Print the dependency list with no duplicates"
 	echo
 	echo "  -h, --help                 Print this help message"
 	echo "  -v, --version              Print the program name and version"
 	echo
-	echo "Example: $prog_name -c -d 2 readline"
+	echo "Example: $prog_name -c -d2 readline"
 }
 
 _version(){
@@ -140,7 +141,16 @@ _tree(){
 
 		if [[ ! " ${dep_list[@]} " =~ " $pkg_name " ]] && [ $spaces -ne $max_depth ]; then
 			dep_list=( "${dep_list[@]}" "$pkg_name" )
-			for dep_pkg in $(_grabfield "$pkg_dir/depends" %DEPENDS%); do
+			if [ $reversed_dep -eq 0 ]; then
+				deps_pkg="$(_grabfield "$pkg_dir/depends" %DEPENDS%)"
+			else
+				reqs_pkg_dir="$(_finddep "$pkg_name" %DEPENDS% depends)"
+				unset deps_pkg
+				for req_pkg_dir in $reqs_pkg_dir; do
+					deps_pkg=$(echo "$deps_pkg" "$(_grabfield "$req_pkg_dir/desc" %NAME%)")
+				done
+			fi
+			for dep_pkg in $deps_pkg; do
 				spaces=$2		#Bash scoping ;_;
 				if [ $graphviz -eq 1 ]; then
 					echo "\"$1\" -> \"${dep_pkg%%[<>=]*}\" [color=$arrow1_color];"
@@ -208,6 +218,12 @@ for (( n=0 ; n < $len_options ; n++ )); do
 		continue
 	fi
 
+	if [ "${options[$n]}" = "-r" -o "${options[$n]}" = "--reversed" ]; then
+		unset options[$n]
+		reversed_dep=1
+		continue
+	fi
+
 	if [[ "${options[$n]}" =~ -d[[:digit:]]+ || "${options[$n]}" == "--depth" ]]; then
 		if [[ "${options[$n]#-d}" =~ [[:digit:]]+ ]]; then
 			max_depth="${options[$n]#-d}"
@@ -229,6 +245,7 @@ linear=${linear:-0}
 silent=${silent:-0}
 nodup=${nodup:-0}
 graphviz=${graphviz:-0}
+reversed_dep=${reversed_dep:-0}
 
 if [ $colored -ne 1 ]; then
 	unset branch1_color
@@ -292,8 +309,12 @@ if [ $graphviz -eq 1 ]; then
 	root_pkgs="${options[@]}"
 	# Uncomment for the "generated by pactree" node in graphviz
 	#advert="xyz [height=0.07, fontsize=8.0, label=\"GENERATED WITH PACTREE\",shape=box,color="black",style=filled,fontcolor="white"];\n"
-
-	echo -e "digraph G { START [color=$start_color, style=filled];\n node [style=filled, color=$nodes_color];\n$(_main)\n$advert}" | dot -T$gformat -o "${root_pkgs// /_}.deps.$gformat"
+	if [ $reversed_dep -eq 0 ]; then
+		file_extension="deps.$gformat"
+	else
+		file_extension="reqs.$gformat"
+	fi
+	echo -e "digraph G { START [color=$start_color, style=filled];\n node [style=filled, color=$nodes_color];\n$(_main)\n$advert}" | dot -T$gformat -o "${root_pkgs// /_}.$file_extension"
 else _main
 fi
 
-- 
1.7.0.5




More information about the pacman-dev mailing list