summaryrefslogtreecommitdiff
path: root/bin/apt-why
blob: 9af72831a63affda233bf5a50c0f9a745f85dc2a (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
83
84
#!/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> [ B<--not> ] I<package>

=head1 DESCRIPTION

B<apt-why> displays various informations based on a I<package>s reverse
dependencies

The output is prefixed by two charactes, the former representing the desired
package state, the latter the current state.

The states are I<i>nstall, I<h>old, I<r>emove (deinstall), I<p>urge,
I<u>npacked, halI<f> configured, I<h>alf installed, I<c>onfigfiles installed.
An empty field means not installed.

If B<--not> is specified, reverse dependencies prohibiting the installation of
I<package> are shown. Else, reverse dependencies justifying the installation
of I<package> are shown

=head1 AUTHOR

Daniel Friesel <derf@derf.homelinux.org>

=head1 LICENSE

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