| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# |
| 4 |
# Output a dot graph of installed reverse dependencies for a package. |
| 5 |
# |
| 6 |
|
| 7 |
use strict; |
| 8 |
use warnings; |
| 9 |
|
| 10 |
use AptPkg::Config '$_config'; |
| 11 |
use AptPkg::System '$_system'; |
| 12 |
use AptPkg::Cache; |
| 13 |
|
| 14 |
use Getopt::Long; |
| 15 |
|
| 16 |
(my $self = $0) =~ s#.*/##; |
| 17 |
|
| 18 |
# Default is to include recommended packages, but not suggested. |
| 19 |
my %want; |
| 20 |
$want{$_} = 1 for (AptPkg::Dep::Depends, AptPkg::Dep::PreDepends, |
| 21 |
AptPkg::Dep::Recommends); |
| 22 |
$want{$_} = 0 for (AptPkg::Dep::Suggests); |
| 23 |
|
| 24 |
die "Usage: $self [--suggests] [--norecommends] PACKAGE\n" |
| 25 |
unless GetOptions('suggests!' => \$want{AptPkg::Dep::Suggests}, |
| 26 |
'recommends!' => \$want{AptPkg::Dep::Recommends}) |
| 27 |
and @ARGV == 1; |
| 28 |
|
| 29 |
$_config->init; |
| 30 |
$_system = $_config->system; |
| 31 |
$_config->{quiet} = 2; |
| 32 |
|
| 33 |
my $cache = AptPkg::Cache->new; |
| 34 |
my @todo = @ARGV; |
| 35 |
my %deps; |
| 36 |
my %seen; |
| 37 |
|
| 38 |
do { |
| 39 |
my @next; |
| 40 |
for my $pack (@todo) { |
| 41 |
my $p = $cache->{$pack} or next; |
| 42 |
next unless $p->{CurrentState} == AptPkg::State::Installed; |
| 43 |
my $revdeps = $p->{RevDependsList} or next; |
| 44 |
my @instrevdeps; |
| 45 |
for my $r (map $_->{ParentPkg}{ShortName}, |
| 46 |
grep $want{0+$_->{DepType}}, |
| 47 |
@$revdeps) { |
| 48 |
next if $seen{$r}++; |
| 49 |
$p = $cache->{$r} or next; |
| 50 |
push @instrevdeps, $r if $p->{CurrentState} == AptPkg::State::Installed; |
| 51 |
} |
| 52 |
next unless @instrevdeps; |
| 53 |
$deps{$pack} = \@instrevdeps; |
| 54 |
push @next, @instrevdeps; |
| 55 |
} |
| 56 |
@todo = @next; |
| 57 |
} while (@todo); |
| 58 |
|
| 59 |
$\ = "\n"; |
| 60 |
|
| 61 |
print "digraph deps {"; |
| 62 |
while (my ($p, $d) = each %deps) { |
| 63 |
print qq/ "$_" -> "$p"/ for @$d; |
| 64 |
} |
| 65 |
print "}"; |