#!/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 $all = 0; my @deptypes = ('Depends', 'Recommends', 'Suggests'); GetOptions( 'all!' => \$all, 'deptype=s' => sub {shift; @deptypes = split(/,/, shift)}, 'depth=i' => \$max_depth, 'h|?|help' => \&usage, ); my $packagename = shift or die("No packagename given"); my @known; sub usage { exec('perldoc', '-F', $0) or die("See perldoc -F $0"); } sub revdeps { my $name = shift; my $package = $cache->{$name}; my @return; my $rdeps = $package->{RevDependsList}; foreach (@$rdeps) { if ( not $_->{ParentPkg}{Name} ~~ @known and ($all or $cache->{$_->{ParentPkg}{Name}}->{CurrentState} eq 'Installed') and "$_->{DepType}" ~~ @deptypes ) { 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 installed packages require I on the system. =head1 OPTIONS =over =item B<--all> Consider all packages, not just installed ones =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. =back =head1 AUTHOR Daniel Friesel =head1 LICENSE 0. You just DO WHAT THE FUCK YOU WANT TO.