[Pkg-asv-commits] r17 - trunk
ahoenen-guest at alioth.debian.org
ahoenen-guest at alioth.debian.org
Sat Jan 12 14:15:22 UTC 2008
Author: ahoenen-guest
Date: 2008-01-12 14:15:22 +0000 (Sat, 12 Jan 2008)
New Revision: 17
Modified:
trunk/apt-show-versions
Log:
In order to prepare some extensive code changes, normalize tabs/spaces and
indentation:
- Normalize:
- perltidy --indent-only --noblanks-before-comments apt-show-versions
- expand apt-show-versions.tdy > apt-show-versions
- rm apt-show-versions.tdy
- Check:
- svn diff -x -w -r 16 apt-show-versions
Modified: trunk/apt-show-versions
===================================================================
--- trunk/apt-show-versions 2008-01-02 17:03:07 UTC (rev 16)
+++ trunk/apt-show-versions 2008-01-12 14:15:22 UTC (rev 17)
@@ -57,17 +57,17 @@
# in hash %pkg_names as a key (with a true value).
my %pkg_names = ();
unless (GetOptions (\%opts,
- 'status-file|stf=s',
- 'list-dir|ld=s',
- 'package|p=s',
- 'regex|r',
- 'allversions|a',
- 'upgradeable|u',
- 'brief|b',
- 'nohold|nh',
- 'initialize|i',
- 'verbose|v',
- 'help|h')) {
+ 'status-file|stf=s',
+ 'list-dir|ld=s',
+ 'package|p=s',
+ 'regex|r',
+ 'allversions|a',
+ 'upgradeable|u',
+ 'brief|b',
+ 'nohold|nh',
+ 'initialize|i',
+ 'verbose|v',
+ 'help|h')) {
exit 1;
}
if (scalar @ARGV == 1) {
@@ -87,7 +87,7 @@
Apt-Show-Versions v.$VERSION (c) Christoph Martin
Usage:
- apt-show-versions shows available versions of installed packages.
+ apt-show-versions shows available versions of installed packages.
Options:
-stf|--status-file=<file> Use <file> as the dpkg status file instead
@@ -100,21 +100,21 @@
-a|--allversions Print all available versions.
-b|--brief Short output.
-nh|--nohold Don't treat holded packages.
- -i|--initialize Initialize or update package cache only (as root).
+ -i|--initialize Initialize or update package cache only (as root).
-v|--verbose Verbose messages.
-h|--help Print this help.
EOF
-# ' (make emacs perl-mode happy)
+ # ' (make emacs perl-mode happy)
exit;
}
# Path to apt's list files
my $list_dir;
if ($opts{'list-dir'}) {
- $list_dir = $opts{'list-dir'};
+ $list_dir = $opts{'list-dir'};
}
else {
- $list_dir = $_config->get_dir("Dir::State::lists");
+ $list_dir = $_config->get_dir("Dir::State::lists");
}
# Path to dpkg status file
@@ -139,7 +139,7 @@
opendir(DIR, $list_dir) or die "Can't opendir $list_dir: $!";
@files = map { $list_dir . $_} grep /Packages$/, readdir(DIR);
($< == 0) and (store(\@files, $filescachefile) or
- warn "Can't write $filescachefile");
+ warn "Can't write $filescachefile");
}
unless (scalar @files > 0) {die "Error: No information about packages! (Maybe no deb entries?)\n"};
closedir DIR ;
@@ -154,7 +154,7 @@
if (!-e $ipackagescachefile or -M $status_file < -M $ipackagescachefile or !ref($ipackages)) {
$ipackages = parse_file ($status_file, 1);
($< == 0) and (store($ipackages, $ipackagescachefile) or
- warn "Can't write $ipackagescachefile");
+ warn "Can't write $ipackagescachefile");
}
# Get available packages list from cache if possible
@@ -180,10 +180,10 @@
$release = quotemeta $release;
my $archiv;
$archiv = `fgrep -s Archive $release` or
- $archiv = `fgrep -s Suite $release` or
- ($release =~ /(potato|woody|sarge|etch|lenny|sid|stable|testing|unstable|experimental)/ and $archiv = $1) or
- $archiv = "unknown";
-# next;
+ $archiv = `fgrep -s Suite $release` or
+ ($release =~ /(potato|woody|sarge|etch|lenny|sid|stable|testing|unstable|experimental)/ and $archiv = $1) or
+ $archiv = "unknown";
+ # next;
$archiv =~ s/Archive: //;
$archiv =~ s/Suite: //;
$archiv =~ s/\n//;
@@ -191,43 +191,43 @@
# Parse Packages file if creation time is newer than packages cache
if (! -e $apackagescachefile or -C $_ < -M $apackagescachefile or $cache_file_corrupt) {
- my $href = &parse_file ($_);
- foreach (keys %$href) {
-# if ((defined $apackages->{$_}{$archiv}) &&
-# exists $opts{'package'} &&
-# !exists $opts{'regex'} &&
-# $opts{'package'} eq $_ ) {
-# print "DEBUG: " . $apackages->{$_}{$archiv}->{'Version'} .
-# ":" . $href->{$_}->{'Version'} .
-# ":" . $vs->compare($apackages->{$_}{$archiv}->{'Version'},
-# $href->{$_}->{'Version'}) . "\n";
-# }
- # skip packages which we don't want to see
-# next unless (!exists $opts{'package'} ||
-# ((exists $opts{'regex'} &&
-# ($href->{$_}->{'Package'} =~ m/$opts{'package'}/)) ||
-# ($href->{$_}->{'Package'} eq $opts{'package'})));
- # skip package info with same release but smaler version
- if ((defined $apackages->{$_}{$archiv}) and
- ($vs->compare($apackages->{$_}{$archiv}->{'Version'},
- $href->{$_}->{'Version'}) > 0)) {
- if ((exists $opts{'package'}
- and not exists $opts{'regex'}
- and $opts{'package'} eq $_)
- or $pkg_names{$_}) {
-# print "DEBUG: " . $apackages->{$_}{$archiv}->{'Version'} .
-# ":" . $href->{$_}->{'Version'} . " next\n";
- }
- next;
- }
- # add package info together with release to hash
- $apackages->{$_}{$archiv} = $href->{$_};
- }
+ my $href = &parse_file ($_);
+ foreach (keys %$href) {
+ # if ((defined $apackages->{$_}{$archiv}) &&
+ # exists $opts{'package'} &&
+ # !exists $opts{'regex'} &&
+ # $opts{'package'} eq $_ ) {
+ # print "DEBUG: " . $apackages->{$_}{$archiv}->{'Version'} .
+ # ":" . $href->{$_}->{'Version'} .
+ # ":" . $vs->compare($apackages->{$_}{$archiv}->{'Version'},
+ # $href->{$_}->{'Version'}) . "\n";
+ # }
+ # skip packages which we don't want to see
+ # next unless (!exists $opts{'package'} ||
+ # ((exists $opts{'regex'} &&
+ # ($href->{$_}->{'Package'} =~ m/$opts{'package'}/)) ||
+ # ($href->{$_}->{'Package'} eq $opts{'package'})));
+ # skip package info with same release but smaler version
+ if ((defined $apackages->{$_}{$archiv}) and
+ ($vs->compare($apackages->{$_}{$archiv}->{'Version'},
+ $href->{$_}->{'Version'}) > 0)) {
+ if ((exists $opts{'package'}
+ and not exists $opts{'regex'}
+ and $opts{'package'} eq $_)
+ or $pkg_names{$_}) {
+ # print "DEBUG: " . $apackages->{$_}{$archiv}->{'Version'} .
+ # ":" . $href->{$_}->{'Version'} . " next\n";
+ }
+ next;
+ }
+ # add package info together with release to hash
+ $apackages->{$_}{$archiv} = $href->{$_};
+ }
}
}
# Store if we are root
($< == 0) and (store($apackages, $apackagescachefile) or
- die "Warning: Can't write to $apackagescachefile!\n");
+ die "Warning: Can't write to $apackagescachefile!\n");
# Exit if we are root and using the -i option
($< == 0) and (exists $opts{'initialize'}) and exit;
@@ -247,8 +247,8 @@
# print info for all packages or packages matching regex
foreach my $key (keys %$ipackages) {
next if (exists $opts{'package'} &&
- exists $opts{'regex'} &&
- !($key =~ m/$opts{'package'}/));
+ exists $opts{'regex'} &&
+ !($key =~ m/$opts{'package'}/));
print_package ($key);
}
@@ -265,68 +265,67 @@
if ($cmp_versions != 0) {
my $direction = ($cmp_versions > 0) ? 'up' : 'down';
print "$package/$archiv"
- . (!defined($opts{'brief'})
- ? " ${direction}gradeable from $iversion to $aversion\n"
- : "\n");
+ . (!defined($opts{'brief'})
+ ? " ${direction}gradeable from $iversion to $aversion\n"
+ : "\n");
return 1;
}
elsif ($cmp_versions == 0) {
print "$package/$archiv"
- . (!defined($opts{'brief'})
- ? " uptodate $iversion\n"
- : "\n")
- unless (defined $opts{'upgradeable'});
+ . (!defined($opts{'brief'})
+ ? " uptodate $iversion\n"
+ : "\n")
+ unless (defined $opts{'upgradeable'});
return 1;
}
}
-# print "DEBUG: $package/$archiv $aversion:$iversion\n";
+ # print "DEBUG: $package/$archiv $aversion:$iversion\n";
return 0;
}
# print information about package
-
sub print_package {
my ($package) = @_;
- #
+ #
my @releases = ();
# Only report on release we found
# include official releases first
foreach (@official_releases) {
- if (exists $releases{$_}) {
- push @releases, $_;
- }
+ if (exists $releases{$_}) {
+ push @releases, $_;
+ }
}
# include also other releases
foreach (keys %releases) {
- push @releases, $_
- unless $official_releases{$_};
+ push @releases, $_
+ unless $official_releases{$_};
}
# print more information if required
if ($opts{'allversions'}) {
- if ($ipackages->{$package}->{'Package'}) {
- print $ipackages->{$package}->{'Package'}, "\t";
- unless ($ipackages->{$package}->{'Status'} =~ /not-installed/ ||
- $ipackages->{$package}->{'Status'} =~ /config-files/) {
- print "$ipackages->{$package}->{'Version'}\t";
- }
- print "$ipackages->{$package}->{'Status'}\n";
- } else {
- print "Not installed\n";
- }
+ if ($ipackages->{$package}->{'Package'}) {
+ print $ipackages->{$package}->{'Package'}, "\t";
+ unless ($ipackages->{$package}->{'Status'} =~ /not-installed/ ||
+ $ipackages->{$package}->{'Status'} =~ /config-files/) {
+ print "$ipackages->{$package}->{'Version'}\t";
+ }
+ print "$ipackages->{$package}->{'Status'}\n";
+ } else {
+ print "Not installed\n";
+ }
-# foreach ("stable", "testing", "unstable") {
- foreach (@releases) {
- if (defined $apackages->{$package}{$_}) {
- print $apackages->{$package}{$_}->{'Package'}, "\t";
- print $apackages->{$package}{$_}->{'Version'}, "\t";
- print $_, "\n";
- } else {
- print "No $_ version\n"
- if $official_releases{$_};
- }
- }
+ # foreach ("stable", "testing", "unstable") {
+ foreach (@releases) {
+ if (defined $apackages->{$package}{$_}) {
+ print $apackages->{$package}{$_}->{'Package'}, "\t";
+ print $apackages->{$package}{$_}->{'Version'}, "\t";
+ print $_, "\n";
+ } else {
+ print "No $_ version\n"
+ if $official_releases{$_};
+ }
+ }
}
my $iversion = $ipackages->{$package}->{'Version'};
@@ -334,18 +333,18 @@
# print info about upgrade status (only if package is installed)
if (($ipackages->{$package}->{'Version'}) &&
- (!($ipackages->{$package}->{'Status'} =~ /config-files/))) {
- my $found = 0;
- my $aversion = 0;
- foreach (@releases) {
- my $version = $apackages->{$package}{$_}->{'Version'};
- if ($version) {
- $found = print_version($_, $package, $iversion, $version);
- $aversion = $version;
- }
- last if $found;
- }
- if ($aversion && ($vs->compare($iversion, $aversion) > 0)) {
+ (!($ipackages->{$package}->{'Status'} =~ /config-files/))) {
+ my $found = 0;
+ my $aversion = 0;
+ foreach (@releases) {
+ my $version = $apackages->{$package}{$_}->{'Version'};
+ if ($version) {
+ $found = print_version($_, $package, $iversion, $version);
+ $aversion = $version;
+ }
+ last if $found;
+ }
+ if ($aversion && ($vs->compare($iversion, $aversion) > 0)) {
# Test whether installed version is newer
# than all available versions.
my $newer_indic = 1;
@@ -362,28 +361,28 @@
{
print "$package $iversion newer than version in archive\n";
}
- } else {
- unless ($found || (defined $opts{'upgradeable'})) {
- print "$package $iversion installed: No available version in archive\n";
- }
- }
+ } else {
+ unless ($found || (defined $opts{'upgradeable'})) {
+ print "$package $iversion installed: No available version in archive\n";
+ }
+ }
} else {
-# print "$package not installed: No available versions\n";
- print "$package not installed\n";
+ # print "$package not installed: No available versions\n";
+ print "$package not installed\n";
}
-
-# my $sversion = $apackages->{$package}{"stable"}->{'Version'};
-# my $tversion = $apackages->{$package}{"testing"}->{'Version'};
-# my $uversion = $apackages->{$package}{"unstable"}->{'Version'};
+ # my $sversion = $apackages->{$package}{"stable"}->{'Version'};
+ # my $tversion = $apackages->{$package}{"testing"}->{'Version'};
+ # my $uversion = $apackages->{$package}{"unstable"}->{'Version'};
+
# print info about upgrade status (only if package is installed)
-# if ($ipackages->{$package}->{'Version'}) {
-# print_version("stable", $package, $iversion, $sversion) ||
-# print_version("testing", $package, $iversion, $tversion) ||
-# print_version("unstable", $package, $iversion, $uversion) ||
-# (defined $opts{'upgradeable'}) ||
-# print "$package: No available version\n";
-# }
+ # if ($ipackages->{$package}->{'Version'}) {
+ # print_version("stable", $package, $iversion, $sversion) ||
+ # print_version("testing", $package, $iversion, $tversion) ||
+ # print_version("unstable", $package, $iversion, $uversion) ||
+ # (defined $opts{'upgradeable'}) ||
+ # print "$package: No available version\n";
+ # }
}
# ------------------------------------------------------
@@ -396,45 +395,45 @@
# ------------------------------------------------------
sub parse_file {
- my ($file, $status) = @_;
- my ($key, $value, $package, $packages);
+ my ($file, $status) = @_;
+ my ($key, $value, $package, $packages);
- open FILE, $file or die "Can't open file $file: $!";
- if ($opts{'verbose'}) {print "Parsing $file...";};
- while (<FILE>) {
- if (/^$/){
- unless (defined $package) {next};
+ open FILE, $file or die "Can't open file $file: $!";
+ if ($opts{'verbose'}) {print "Parsing $file...";};
+ while (<FILE>) {
+ if (/^$/){
+ unless (defined $package) {next};
- if ($status) { # Are we parsing the status file?
- # if we did not specify a package or pattern
- # only include installed packages
- unless ((!exists $opts{'package'} && !%pkg_names &&
- ($package->{'Status'} =~ /not-installed/ ||
- $package->{'Status'} =~ /config-files/ ||
- # don't print holded packages if requested
- ($opts{'nohold'} && $package->{'Status'} =~ /hold/)))) {
- $packages->{ $package->{'Package'}} = $package;
- }
- }
- else {
- if (!defined $packages->{$package->{'Package'}} or
- $vs->compare($packages->{$package->{'Package'}}{'Version'},
- $package->{'Version'}) < 0) {
- $packages->{$package->{'Package'}} = $package;
- }
- }
- undef $package;
- next;
- }
- unless ((/^Package/) || (/^Version/) || (/^Status/) || (/^Source/)) {next};
- ($key, $value) = split /: /, $_;
- $value =~ s/\n//;
- $value =~ s/\s\(.*\)$//; # Remove any Version information in ()
- $package->{$key} = $value;
- }
- if ($opts{'verbose'}) {print " completed.\n"};
- close FILE;
- return $packages;
+ if ($status) { # Are we parsing the status file?
+ # if we did not specify a package or pattern
+ # only include installed packages
+ unless ((!exists $opts{'package'} && !%pkg_names &&
+ ($package->{'Status'} =~ /not-installed/ ||
+ $package->{'Status'} =~ /config-files/ ||
+ # don't print holded packages if requested
+ ($opts{'nohold'} && $package->{'Status'} =~ /hold/)))) {
+ $packages->{ $package->{'Package'}} = $package;
+ }
+ }
+ else {
+ if (!defined $packages->{$package->{'Package'}} or
+ $vs->compare($packages->{$package->{'Package'}}{'Version'},
+ $package->{'Version'}) < 0) {
+ $packages->{$package->{'Package'}} = $package;
+ }
+ }
+ undef $package;
+ next;
+ }
+ unless ((/^Package/) || (/^Version/) || (/^Status/) || (/^Source/)) {next};
+ ($key, $value) = split /: /, $_;
+ $value =~ s/\n//;
+ $value =~ s/\s\(.*\)$//; # Remove any Version information in ()
+ $package->{$key} = $value;
+ }
+ if ($opts{'verbose'}) {print " completed.\n"};
+ close FILE;
+ return $packages;
}
# script documentation (POD style)
More information about the Pkg-asv-commits
mailing list