summaryrefslogtreecommitdiff
path: root/bin/apt-why
blob: 37d0fde7b29d846a3ecd0ef6baca60bdaf1da508 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env perl
## Copyright © 2008-2009 by Daniel Friesel <derf@derf.homelinux.org>
## License: WTFPL <http://sam.zoy.org/wtfpl>
use strict;
use warnings;
use AptPkg::Cache;
use Switch;
use Getopt::Long;

my $cache = AptPkg::Cache->new;
my $not = 0;
my @deptypes;
GetOptions(
	'not' => \$not,
	'deptype=s' => \@deptypes,
);
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 $level = (shift) + 1;
	printf("%s%s\n", "  " x ($level-1), $name);
	return if ($level >= 5);
	recurse($_, $level) foreach revdeps($name);
}

recurse($packagename, 0);

__END__

=head1 NAME

apt-why - filtered reverse dependency displayer using AptPkg::Cache

=head1 SYNOPSIS

B<apt-why> [ I<options> ] I<package>

=head1 DESCRIPTION

B<apt-why> recursively displays I<package>'s reverse dependency, thus
showing which packages require I<package> on the system.

=head1 OPTIONS

=over

=item B<--deptype>=I<types>

Only show reverse dependency which mach the specified I<types> (comma separated list).
Right now, possible types are Depends, Suggests, Recommends.

=head1 AUTHOR

Daniel Friesel <derf@derf.homelinux.org>

=head1 LICENSE

  0. You just DO WHAT THE FUCK YOU WANT TO.