File: pkg-revdeps

package info (click to toggle)
pkg-order 1.02
  • links: PTS
  • area: main
  • in suites: hamm, slink
  • size: 484 kB
  • ctags: 172
  • sloc: perl: 4,094; makefile: 81
file content (212 lines) | stat: -rwxr-xr-x 5,042 bytes parent folder | download | duplicates (2)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#! /usr/bin/perl -w
#                              -*- Mode: Perl -*- 
# pkg-revdeps --- 
# Author           : Manoj Srivastava ( srivasta@tiamat.datasync.com ) 
# Created On       : Wed Jul 16 14:35:20 1997
# Created On Node  : tiamat.datasync.com
# Last Modified By : Manoj Srivastava
# Last Modified On : Sat Jul 19 00:17:31 1997
# Last Machine Used: tiamat.datasync.com
# Update Count     : 43
# Status           : Unknown, Use with caution!
# HISTORY          : 
# Description      : 
# 
# 

use strict;
use diagnostics;
use Carp;
require 5.001;

use Debian::Package::Dependency_List;
use Debian::Package::Package;
use Debian::Package::List;
use Getopt::Long;

package main;


#Handle The auto generated eval line.
use vars qw($running_under_some_shell);

=head1 NAME

pkg-revdeps - A Package reverse dependency pretty printing tool.

=cut

=head1 SYNOPSIS

 usage: pkg-revdeps [options] [reg-exp [reg-expr...]]
 where the options are:

=over 2

=item --nocheck-recommends 

=item --check-recommends   Check Recommends as well [OFF]

=item --nocheck-suggests

=item --check-suggests     Check Suggests as well   [OFF]

=item --installed-packages <Package-file-for-installed-packages> 

=back

=cut

=head1 DESCRIPTION

This utility prints out a dependency tree of installed packages,
optionally taking a list of space separated regular expressions on the
command line to limit the starting points. If no regular expressions
are given, then all installed packages shall be displayed.

 The default is to assume that the list of installed packages may be
 derived from the file I</var/lib/dpkg/status>, but the user may
 override this by providing a I<Packages> file listing all the
 packages that are assumed to be installed.

=cut 

sub main {
  my $installed;
  my $candidates;
  my $ret;
  my $recommends = 0;
  my $suggests = 0;
  my $consistent = 1;
  my $usage = '';
  my $MYNAME = '';
  my $list = '';
  my $installed_packages = '';
  
  ($MYNAME     = $0) =~ s|.*/||;


  $usage= <<EOUSAGE;
 usage: $MYNAME [options] <Package-file-for-new-packages>
 where the options are:
 --nocheck-recommends
 --check-recommends   Check the Recommends field as well            [OFF]
 --nocheck-suggests
 --check-suggests     Check the Suggests field as well              [OFF]
 --installed-packages <Package-file-for-installed-packages> 
EOUSAGE
  
  $ret = GetOptions("check-recommends!"   => \$recommends,
                    "check-suggests!"     => \$suggests,
		    "installed-packages=s" => \$installed_packages);

  die "$usage" unless $ret;
  
  ######################################################################
  #                     Phase One: Gather data                         #
  ######################################################################

  # Installed file (default value, taken from status file)
  if (-f $installed_packages) {
    $installed = Debian::Package::New->new('filename' => $installed_packages);
    $candidates  = Debian::Package::New->new('filename' => $installed_packages);
  }
  else {
    $installed = Debian::Package::Installed->new();
    $candidates = Debian::Package::Installed->new();
  }
  
  $candidates->get_dependency_information();

  my $order_string = $candidates->names_as_string();

  my @ordered_list = split(' ', $order_string);
  my %Done = ();
  my $pkg = '';
  
  foreach $pkg (@ordered_list) {
    next if $Done{$pkg} && $Done{$pkg} > 1;
    next unless $candidates->{$pkg}->{'Package'};
    if ($#ARGV > -1) {
      my $match = '';
      for (@ARGV) {
	if ($pkg =~ m/$_/) {
	  $match = 1;
	  last;
	}
      }
      next unless $match;
    }

    print_depends('Candidates' => $candidates,
		  'Package' => $pkg,
		  'Level' => 0,
		  'Recommends' => $recommends,
		  'Suggests' => $suggests,
		  'Done' => \%Done);
  }
  exit 0;
}

sub print_depends{
  my %params = @_;
  my $targets = '';
  my @targets = ();
  my $pkg = '';
  
  print "  " x $params{'Level'}, "$params{'Package'}\n";
  if (defined $params{'Done'}->{$params{'Package'}}) {
    $params{'Done'}->{$params{'Package'}} += 1;
  }
  else {
    $params{'Done'}->{$params{'Package'}} = 1;
  }

  return if $params{'Done'}->{$params{'Package'}} > 1;

  my @Types = ('Pre-Depends', 'Depends');
  push (@Types, 'Recommends') if $params{'Recommends'};
  push (@Types, 'Suggests')   if $params{'Suggests'};
  
  for (@Types) {
    if (defined $params{'Candidates'}->{$params{'Package'}}->{$_}) {
      $targets .=
	$params{'Candidates'}->{$params{'Package'}}->{$_};
    }
  }
  
  @targets = split(',', $targets);
  foreach $pkg (@targets) {
    $pkg =~ s/\([^\)]*\)//g;
    $pkg =~ s/\s*//go;

    next unless $params{'Candidates'}->{$pkg}->{'Package'};
    
    print_depends('Candidates' => $params{'Candidates'},
		  'Package' => $pkg,
		  'Level' => $params{'Level'} + 1,
		  'Done' => $params{'Done'});
  }
}

=head1 CAVEATS

This is very inchoate, at the moment, and needs testing.

=cut

=head1 BUGS

None Known so far.

=cut

=head1 AUTHOR

Manoj Srivastava <srivasta@debian.org>

=cut

&main::main();