#!/usr/bin/env perl ## Copyright © 2008-2009 by Daniel Friesel ## License: WTFPL use strict; use warnings; use 5.010; use AptPkg::Cache; use Switch; use Getopt::Long; my $cache = AptPkg::Cache->new; my $max_depth = 5; my @deptypes; GetOptions( 'deptype=s' => \@deptypes, 'depth=i' => \$max_depth, ); my $packagename = shift or die("No packagename given"); my @known; @deptypes = split(/,/, join(',', @deptypes)); sub revdeps { my $name = shift; my $package = $cache->{$name}; my @return; my $rdeps = $package->{RevDependsList}; foreach (@$rdeps) { if ( $cache->{$_->{ParentPkg}{Name}}->{CurrentState} eq 'Installed' and ( (not @deptypes and $_->{DepType} !~ /^(Conflicts|Replaces|Obsoletes)$/) or (@deptypes and "$_->{DepType}" ~~ @deptypes) ) ) { next if ($_->{ParentPkg}{Name} ~~ @known); push(@return, $_->{ParentPkg}{Name}); } } push(@known, @return); return(@return); } sub recurse { my $name = shift; my $depth = (shift) + 1; printf("%s%s\n", " " x ($depth-1), $name); return if ($depth >= $max_depth); recurse($_, $depth) foreach revdeps($name); } recurse($packagename, 0); __END__ =head1 NAME apt-why - filtered reverse dependency displayer using AptPkg::Cache =head1 SYNOPSIS B [ I ] I =head1 DESCRIPTION B recursively displays I's reverse dependency, thus showing which packages require I on the system. =head1 OPTIONS =over =item B<--depth>=I (default: 5) Specify the maximum recursion depth =item B<--deptype>=I Only show reverse dependency which mach the specified I (comma separated list). Right now, possible types are Depends, Suggests, Recommends. =head1 AUTHOR Daniel Friesel =head1 LICENSE 0. You just DO WHAT THE FUCK YOU WANT TO.