File: apt-cache

package info (click to toggle)
libapt-pkg-perl 0.1.13
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 236 kB
  • ctags: 101
  • sloc: perl: 1,063; ansic: 198; makefile: 39
file content (139 lines) | stat: -rwxr-xr-x 2,649 bytes parent folder | download
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
#!/usr/bin/perl

#
# $Id: apt-cache,v 1.2 2003/07/19 04:00:35 bod Exp $
#
# Example: demonstrate accessing the package cache
#
# Usage: apt-cache PACKAGE
#

use AptPkg::Config '$_config';
use AptPkg::System '$_system';
use AptPkg::Cache;

(my $self = $0) =~ s#.*/##;

# initialise the global config object with the default values and
# setup the $_system object
$_config->init;
$_system = $_config->system;

# supress cache building messages
$_config->{quiet} = 2;

# set up the cache
my $cache = AptPkg::Cache->new;

die "Usage: $self PACKAGE ...\n" unless @ARGV;

for my $pack (@ARGV)
{
    my $p = $cache->{$pack};
    unless ($p)
    {
	warn "$self: don't know anything about package `$pack'\n";
	next;
    }

    print "Package: $pack\n";
    for my $field (qw/Section SelectedState InstState CurrentState Flags/)
    {
	print "$field: $p->{$field}\n" if $p->{$field};
    }

    print "CurrentVer: $p->{CurrentVer}{VerStr}\n" if $p->{CurrentVer};

    if (my $available = $p->{VersionList})
    {
	print "VersionList:\n";
	my $i = 0;
	for my $v (@$available)
	{
	    print "  [$i] $v->{VerStr} (",
		(join ', ', map $_->{File}{FileName}, @{$v->{FileList}}),
		")\n";

	    print "      Priority: $v->{Priority}\n";

	    if (my $deps = $v->{DependsList})
	    {
		my $type = '';
		my $delim = '';

		for my $d (@$deps)
		{
		    if ($d->{DepType} ne $type)
		    {
			print "\n" if $type;
			$type = $d->{DepType};
			print "      $type: ";
		    }
		    else
		    {
			print $delim;
		    }

		    $delim = ($d->{CompType} & AptPkg::Dep::Or) ? ' | ' : ', ';
		    print $d->{TargetPkg}{Name};
		    print " ($d->{CompTypeDeb} $d->{TargetVer})"
			if $d->{TargetVer};
		}

		print "\n";
	    }

	    if (my $p = $v->{ProvidesList})
	    {
		print '      Provides: ', (join ', ', map $_->{Name}, @$p),
		    "\n";
	    }

	    $i++;
	}
    }

    if (my $revdeps = $p->{RevDependsList})
    {
	print "RevDependsList:";
	my $parent = '';
	my $type = '';

	for my $r (@$revdeps)
	{
	    my $new_parent = "$r->{ParentPkg}{Name} $r->{ParentVer}{VerStr}";
	    unless ($new_parent eq $parent)
	    {
		$parent = $new_parent;
		$type = '';
	    }

	    if ($r->{DepType} ne $type)
	    {
		printf "\n  %-30s", $type ? '' : $parent;
		$type = $r->{DepType};
		print "  $type: ";
	    }
	    else
	    {
		print ', ';
	    }

	    print  $r->{TargetPkg}{Name};
	    print  " ($r->{CompTypeDeb} $r->{TargetVer})" if $r->{TargetVer};
	}

	print "\n";
    }

    if (my $provides = $p->{ProvidesList})
    {
	print 'ProvidesList: ', (join ', ',
	    map "$_->{OwnerPkg}{Name} $_->{OwnerVer}{VerStr}", @$provides),
	    "\n";
    }

    print "\n";
}

1;