1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-11-15 13:55:09 -05:00

contrib/pactree: generate reverse dependency trees

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

Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Christophe Chapuis 2010-04-20 16:21:00 +10:00 committed by Dan McGee
parent 652762488a
commit 753599b504

View File

@ -41,7 +41,7 @@ arrow1_color="chocolate4" #color of the normal arrow
arrow2_color="grey" #color of the "provided by" headless arrow arrow2_color="grey" #color of the "provided by" headless arrow
readonly prog_name="pactree" readonly prog_name="pactree"
readonly prog_ver="0.2" readonly prog_ver="0.3"
_usage(){ _usage(){
echo "This program generates the dependency tree of an installed package" 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 " -d, --depth INT Limit the shown dependencies depth"
echo " -g, --graph Use graphviz to make an image of the tree" echo " -g, --graph Use graphviz to make an image of the tree"
echo " -l, --linear Enable linear output" echo " -l, --linear Enable linear output"
echo " -r, --reversed Show reversed dependancies"
echo " -s, --silent Shh, let me hear those errors!" echo " -s, --silent Shh, let me hear those errors!"
echo " -u, --unique Print the dependency list with no duplicates" echo " -u, --unique Print the dependency list with no duplicates"
echo echo
echo " -h, --help Print this help message" echo " -h, --help Print this help message"
echo " -v, --version Print the program name and version" echo " -v, --version Print the program name and version"
echo echo
echo "Example: $prog_name -c -d 2 readline" echo "Example: $prog_name -c -d2 readline"
} }
_version(){ _version(){
@ -140,7 +141,16 @@ _tree(){
if [[ ! " ${dep_list[@]} " =~ " $pkg_name " ]] && [ $spaces -ne $max_depth ]; then if [[ ! " ${dep_list[@]} " =~ " $pkg_name " ]] && [ $spaces -ne $max_depth ]; then
dep_list=( "${dep_list[@]}" "$pkg_name" ) 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 ;_; spaces=$2 #Bash scoping ;_;
if [ $graphviz -eq 1 ]; then if [ $graphviz -eq 1 ]; then
echo "\"$1\" -> \"${dep_pkg%%[<>=]*}\" [color=$arrow1_color];" echo "\"$1\" -> \"${dep_pkg%%[<>=]*}\" [color=$arrow1_color];"
@ -208,6 +218,12 @@ for (( n=0 ; n < $len_options ; n++ )); do
continue continue
fi 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:]]+ || "${options[$n]}" == "--depth" ]]; then
if [[ "${options[$n]#-d}" =~ [[:digit:]]+ ]]; then if [[ "${options[$n]#-d}" =~ [[:digit:]]+ ]]; then
max_depth="${options[$n]#-d}" max_depth="${options[$n]#-d}"
@ -229,6 +245,7 @@ linear=${linear:-0}
silent=${silent:-0} silent=${silent:-0}
nodup=${nodup:-0} nodup=${nodup:-0}
graphviz=${graphviz:-0} graphviz=${graphviz:-0}
reversed_dep=${reversed_dep:-0}
if [ $colored -ne 1 ]; then if [ $colored -ne 1 ]; then
unset branch1_color unset branch1_color
@ -292,8 +309,12 @@ if [ $graphviz -eq 1 ]; then
root_pkgs="${options[@]}" root_pkgs="${options[@]}"
# Uncomment for the "generated by pactree" node in graphviz # 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" #advert="xyz [height=0.07, fontsize=8.0, label=\"GENERATED WITH PACTREE\",shape=box,color="black",style=filled,fontcolor="white"];\n"
if [ $reversed_dep -eq 0 ]; then
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" 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 else _main
fi fi