File: dpkg.pl

package info (click to toggle)
pdbv 2.0.10.1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 436 kB
  • ctags: 52
  • sloc: perl: 1,004; sh: 291; makefile: 129
file content (155 lines) | stat: -rw-r--r-- 4,794 bytes parent folder | download | duplicates (3)
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
# (c) 2002-2005 Mathieu Roy <yeupou@gnu.org>
# dpkg.pl this file is part of package_db_view
#
#   all dpkg commands
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#  take a look at http://gna.org/projects/pdbv
#  send comments at <pdbv-dev@gna.org>
#
#  $Id: dpkg.pl,v 1.23 2005/02/23 10:42:20 yeupou Exp $

print "The purpose of this file is not being executed alone";
exit;

# init values for dpkg
$package_info_baseurl = "http://packages.debian.org/";
$package_installedsize_sum;
$package_explanationurl_priority = "http://www.debian.org/doc/debian-policy/ch-archive.html#s-priorities";
our @package_list;


# init packages raw info list
sub PdbvPackageInit {

    {
	open(STATUS, "$dpkg_dir/status") or die $sbst_unable_to_open."$dpkg_dir/status.\n\nStopped";
	local $/ = '';
	while (<STATUS>) {
	    if (/^Package: / ... /^$/) {
		# Figure out the package name
		my ($pack) = /^Package: (.*)$/m;
		my ($version) = /^Version: (.*)$/m;
		push(@package_list, $pack) if $pack && $version;
		next unless $pack && $version;
		
		# Continue if a package name and version was found, 
		#fill the hashes:
	        # FIXME: extracting conffiles apparently does not work
		($package_conffiles{$pack}) = /^Conffiles: (.*)$/sm;
		($package_configversion{$pack}) = /^Config-Version: (.*)$/m;
		($package_conflicts{$pack}) = /^Conflicts: (.*)$/m;
		($package_depends{$pack}) = /^Depends: (.*)$/m;
		($package_description_short{$pack}) = /^Description: (.*)$/m;
		($package_description{$pack}) = /^Description: (.*)$/sm;
		($package_enhances{$pack}) = /^Enhances: (.*)$/m;
		($package_essential{$pack}) = /^Essential: (.*)$/m;
		($package_installedsize{$pack}) = /^Installed-Size: (.*)$/m;
		($package_installdate{$pack}) = PdbvDate($pack);
		($package_maintainer{$pack}) = /^Maintainer: (.*)$/m;
		($package_origin{$pack}) = /^Origin: (.*)$/m;
		($package_priority{$pack}) = /^Priority: (.*)$/m;
		($package_provides{$pack}) = /^Provides: (.*)$/m;
		($package_recommends{$pack}) = /^Recommends: (.*)$/m;
		($package_section{$pack}) = /^Section: (.*)$/m;
		($package_source{$pack}) = /^Source: (.*)$/m;
		($package_status{$pack}) = /^Status: (.*)$/m;
		($package_suggests{$pack}) = /^Suggests: (.*)$/m;
		($package_version{$pack}) = $version;
		($package_website{$pack}) = /^ Homepage: (.*)$/m;

		# Misc formating stuff
		$package_description{$pack} =~ s/\n \..*/\n/g;
		$package_description{$pack} =~ s/^ Homepage: .*$//gm;

		# Whole database installed-size
		$package_installedsize_sum = ($package_installedsize{$pack} + $package_installedsize_sum);

	    }
	}
	close(STATUS);
    }
    @package_list = sort(@package_list);

    # Get pop-con results, if existing
    if (-e $popcon_file) {
	$package_popularity_activated = 1;
	open(POPCON, $popcon_file);
	while (<POPCON>) {
	    my ($atime, $ctime, $pack) = split(" ", $_);
	    if (/\<OLD\>/) {
		$package_popularity{$pack} = gettext("unused");
		next;
	    }
	    if (/\<RECENT-CTIME\>/) {
		$package_popularity{$pack} = gettext("recently installed");
		next;
	    }
	    if (/\<NOFILES\>/) {
		$package_popularity{$pack} = gettext("with no executable files");
		next;
	    }
	    # If we arrived here, there is relevant data
	    $package_popularity{$pack} = gettext("frequently used");
	}
	close(POPCON);
    }

}

# return the dpkg version
sub PdbvPackagemanagerVersion {
    my $ret = `dpkg --version | head -n 1`;
    chomp($ret);
    $ret =~ s/\.$//;
    return $ret;
}

# return the packages list
sub PdbvPackages { 
    return @package_list;
}

sub PdbvPackagesSorted {
    return @package_list;
}

# return package name without the version
sub PdbvBasename {
    my $ret = $_[0];
    $ret =~ s/\_.*$//g;
    return $ret;
}

# return all files in a package
sub PdbvList {
    my $pack = $_[0];
    my $ret = '';
    if (-e "$dpkg_dir/info/$pack.list") {
	open(LIST, "$dpkg_dir/info/$pack.list") or die $sbst_unable_to_open."$dpkg_dir/info/$pack.list.\n\nStopped";
	while (<LIST>) {
	    $ret .= $_;
	}
	close(LIST);
    }
    return $ret;
}

# return installation date (YYYY Month) of the package
# it can be usefull for list by criterion
sub PdbvDate {
    if (-e "$dpkg_dir/info/".$_[0].".list") {
	my $sb = stat("$dpkg_dir/info/".$_[0].".list");
	my ($sec,$min,$hour,$mday,$month,$year,$sday,$aday,$est_dst) = localtime $sb->mtime;
	return ($year+1900)." ".sprintf("%02d", ($month+1) % 100);
    } else {
	return 0;
    }
}