Commit before big code restructuring.
[rpmdepsize.git] / rpmdepsize.pl
1 #!PERL -w
2 # rpmdepsize - visualize the size of RPM dependencies
3 # (C) Copyright 2009 Red Hat Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 #
19 # Written by Richard W.M. Jones <rjones@redhat.com>
20
21 use strict;
22
23 use Getopt::Long;
24 use Pod::Usage;
25
26 my $man = 0;
27 my $help = 0;
28
29 GetOptions ('help|?' => \$help,
30             'man' => \$man)
31     or pod2usage (2);
32 pod2usage (1) if $help || @ARGV == 0;
33 pod2usage (-exitstatus => 0, -verbose => 2) if $man;
34
35 # Recurse through dependencies until all deps have been found.
36 my %deps;
37
38 foreach (@ARGV) {
39     $deps{$_} = []
40 }
41
42 my $stable = 0;
43 while (!$stable) {
44     $stable = 1;
45     foreach my $name (sort keys %deps) {
46         if (@{$deps{$name}} == 0) {
47             $stable = 0;
48             add_deps ($name);
49         }
50     }
51 }
52
53 sub add_deps
54 {
55     my $name = shift;
56
57     print "resolving deps in $name ...\n";
58
59 # repoquery is incredibly slow.  Unfortunately python has a
60 # privileged position into the yum databases, and a python
61 # script to access this information runs quickly, so this
62 # is what the alternate implementation below uses.
63 #     my $cmd =
64 #       "repoquery --recursive --resolve -R $name |
65 #          sort -u | awk -F- '{print \$1}'";
66
67     my $cmd = "./repodeps $name | grep -v '^Loaded plugins:'";
68
69     open RQ, "$cmd |" or die "$cmd: $!";
70     my $n = 0;
71     while (<RQ>) {
72         chomp;
73         push @{$deps{$name}}, $_;
74         $n++;
75         $deps{$_} = [] unless exists $deps{$_};
76     }
77     close RQ;
78     push @{$deps{$name}}, $name if $n == 0;
79 }
80
81 __END__
82
83 =head1 NAME
84
85  rpmdepsize - Visualize the size of RPM dependencies
86
87 =head1 SYNOPSIS
88
89  rpmdepsize [--options] package [package ...]
90
91 =head1 OPTIONS
92
93 =over 4
94
95 =item B<--help>
96
97 Display short usage message and exit.
98
99 =item B<--man>
100
101 Display manual page and exit.
102
103 =back
104
105 =head1 DESCRIPTION
106
107
108
109
110
111 =head1 HOME PAGE
112
113 L<http://et.redhat.com/~rjones/rpmdepsize>
114
115 =head1 SEE ALSO
116
117 L<rpm(1)>, L<repoquery(1)>, L<dot(1)>.
118
119 =head1 AUTHORS
120
121 Richard W.M. Jones <rjones @ redhat . com>
122
123 =head1 COPYRIGHT
124
125 (C) Copyright 2009 Red Hat Inc.,
126 L<http://et.redhat.com/~rjones/febootstrap>.
127
128 This program is free software; you can redistribute it and/or modify
129 it under the terms of the GNU General Public License as published by
130 the Free Software Foundation; either version 2 of the License, or
131 (at your option) any later version.
132
133 This program is distributed in the hope that it will be useful,
134 but WITHOUT ANY WARRANTY; without even the implied warranty of
135 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
136 GNU General Public License for more details.
137
138 You should have received a copy of the GNU General Public License
139 along with this program; if not, write to the Free Software
140 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
141
142 =cut