[Pkg-asv-commits] r22 - in trunk: . debian

ahoenen-guest at alioth.debian.org ahoenen-guest at alioth.debian.org
Tue Feb 19 20:11:39 UTC 2008


Author: ahoenen-guest
Date: 2008-02-19 20:11:38 +0000 (Tue, 19 Feb 2008)
New Revision: 22

Modified:
   trunk/apt-show-versions
   trunk/debian/changelog
Log:
- Fix suite_idx() for oldstable suite: it must sort first instead of last.
- Emit exit code 2 also for packages without any available version in archive.
- Correct combination of upgradeable and allversions options: If a package is
  not upgradeable, without regard of allversions option nothing gets printed
  for it.


Modified: trunk/apt-show-versions
===================================================================
--- trunk/apt-show-versions	2008-02-17 14:39:15 UTC (rev 21)
+++ trunk/apt-show-versions	2008-02-19 20:11:38 UTC (rev 22)
@@ -274,9 +274,16 @@
     }
 }
 
-# print uptodate or up/downgradeable status of package depending on
-# distribution and return 1 if we had to say anything
-
+################################################################################
+# Collect uptodate or up/downgradeable status of package depending on
+# distribution.  Return: ($version_indicator, @version_info)
+# - $version_indicator:
+#   * 0: Version is not to be installed/kept.
+#   * 1: Version is to be kept.
+#   * 2: Version is to be up/downgraded.
+# - @version_info:
+#   Version information to be printed (undef if no information exists)
+################################################################################
 sub print_version {
     my ($archiv, $package, $iversion, $aversion) = @_;
 
@@ -286,27 +293,17 @@
         my $cmp_versions = $vs->compare($aversion, $iversion);
         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");
-            return 1;
+            return(2, "$package/$archiv", (defined($opts{'brief'})) ? "\n"
+                   : " ${direction}gradeable from $iversion to $aversion\n");
         }
-        elsif ($cmp_versions == 0) {
-            unless (defined $opts{'upgradeable'}) {
-                print("$package/$archiv",
-                      defined($opts{'brief'}) ? "\n" : " uptodate $iversion\n");
-            }
-            elsif ($mode == $MODE_SINGLE) {
-                # Caller expects single given package to be upgradeable.
-                # Signal failure of this expectation with a special exit code.
-                exit 2;
-            }
-            return 1;
+        else {
+            return(1, "$package/$archiv", defined($opts{'brief'}) ? "\n"
+                   : " uptodate $iversion\n");
         }
     }
-    #   print "DEBUG: $package/$archiv $aversion:$iversion\n";
-    return 0;
+    else {
+        return 0;
+    }
 }
 
 # print information about package
@@ -319,26 +316,31 @@
     &determine_pkgfile_release($_) foreach (keys(%{$apackages->{$package}}));
     my @pkg_releases = sort sort_pkg_releases values(%{$apackages->{$package}});
 
+    # All print information of package must be buffered, as the decision
+    # whether to suppress all printing for the package can be executed only at
+    # a later stage.
+    my @print_info = ();
+    my $suppress_print = 0;  # The default case is no suppression.
+    # To guarantee tabular printing of the package's releases some further
+    # variables are needed:
+    my $max_package_len = 0;
+    my $max_version_len = 0;
+
     # print more information if required
     if ($opts{'allversions'}) {
         if ($ipackages->{$package}->{$PACKAGE}) {
-            print "$ipackages->{$package}->{$PACKAGE} ";
+            push @print_info, "$ipackages->{$package}->{$PACKAGE} ";
             unless ($ipackages->{$package}->{$STATUS} =~ /not-installed/ ||
                 $ipackages->{$package}->{$STATUS} =~ /config-files/) {
-                print "$ipackages->{$package}->{$VERSION} ";
+                push @print_info, "$ipackages->{$package}->{$VERSION} ";
             }
-            print "$ipackages->{$package}->{$STATUS}\n";
+            push @print_info, "$ipackages->{$package}->{$STATUS}\n";
         } else {
-            print "Not installed\n";
+            push @print_info, "Not installed\n";
         }
 
         # Index to @official_suites: Next official suite to mention if missing.
         my $official_idx = 0;
-        # To guarantee tabular printing of the package's releases some further
-        # variables are needed:
-        my @print_info = ();
-        my $max_package_len = 0;
-        my $max_version_len = 0;
         # Print preparation loop
         foreach my $pkg (@pkg_releases) {
             # First handle missing official suites to be listed before current
@@ -369,18 +371,6 @@
                 push @print_info, "No $official_suites[$_] version\n";
             }
         }
-        # Print loop
-        foreach my $print_info (@print_info) {
-            if (ref $print_info) {
-                printf("%*s %*s %s\n",
-                       -$max_package_len, $print_info->{$PACKAGE},
-                       -$max_version_len, $print_info->{$VERSION},
-                       $print_info->{$NAME});
-            }
-            else {
-                print $print_info;
-            }
-        }
     }
 
     my $iversion = $ipackages->{$package}->{$VERSION};
@@ -396,12 +386,27 @@
         foreach (@pkg_releases) {
             my $version = $_->{$VERSION};
             if ($version) {
-                $found = print_version($releasenames{$_->{$RELEASE}}{$NAME}, $package,
-                    $iversion, $version);
+                my @version_info;
+                ($found, @version_info) =
+                    &print_version($releasenames{$_->{$RELEASE}}{$NAME},
+                                   $package, $iversion, $version);
+                push @print_info, @version_info if ($found);
                 $aversion = $version;
             }
             last if $found;
         }
+        if ($opts{'upgradeable'} and $found != 2) {
+            if ($mode == $MODE_SINGLE) {
+                # Caller expects single given package to be upgradeable.
+                # Signal failure of this expectation with a special exit code.
+                exit 2;
+            }
+            else {
+                # Upgradeable option is set, but current package is not
+                # upgradeable.  Thus suppress all output for it.
+                $suppress_print = 1;
+            }
+        }
         if ($aversion && ($vs->compare($iversion, $aversion) > 0)) {
             # Test whether installed version is newer
             # than all available versions.
@@ -417,32 +422,33 @@
             }
             if ($newer_indic and not defined($opts{'brief'}))
             {
-                print "$package $iversion newer than version in archive\n";
+                push(@print_info,
+                     "$package $iversion newer than version in archive\n");
             }
-        } else {
-            unless ($found || (defined $opts{'upgradeable'})) {
-                print "$package $iversion installed: No available version in archive\n";
-            }
+        } elsif (not $found) {
+            push(@print_info, "$package $iversion installed: No available ",
+                 "version in archive\n");
         }
     } else {
-        #       print "$package not installed: No available versions\n";
-        print("$package not installed",
-              ($mode == $MODE_SINGLE and not keys(%{$apackages->{$package}}))
-              ? " (even not available)\n" : "\n");
+        push(@print_info, "$package not installed",
+             ($mode == $MODE_SINGLE and not keys(%{$apackages->{$package}}))
+             ? " (even not available)\n" : "\n");
     }
 
-    #    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";
-    #    }
+    # Print loop
+    unless ($suppress_print) {
+        foreach my $print_info (@print_info) {
+            if (ref $print_info) {
+                printf("%*s %*s %s\n",
+                       -$max_package_len, $print_info->{$PACKAGE},
+                       -$max_version_len, $print_info->{$VERSION},
+                       $print_info->{$NAME});
+            }
+            else {
+                print $print_info;
+            }
+        }
+    }
 }
 
 # ------------------------------------------------------
@@ -675,7 +681,8 @@
 # Unofficial suites are sorted last.
 ################################################################################
 sub suite_idx {
-    return($official_suites{$_[0]} || $#official_suites + 1);
+    return(defined($official_suites{$_[0]}) ? $official_suites{$_[0]}
+           : $#official_suites + 1);
 }
 
 ################################################################################

Modified: trunk/debian/changelog
===================================================================
--- trunk/debian/changelog	2008-02-17 14:39:15 UTC (rev 21)
+++ trunk/debian/changelog	2008-02-19 20:11:38 UTC (rev 22)
@@ -1,5 +1,6 @@
 apt-show-versions (0.13) UNRELEASED; urgency=low
 
+  [ Andreas Hoenen ]
   * Replace hardcoded list of supported release names by dynamic determination
     of used release names.  This enables (among others) automatic support for
     oldstable and for inofficial repositories.
@@ -14,11 +15,14 @@
   * When called with exactly one package and upgradeable option set for a
     package that actually is not upgradeable, return with non zero exit code.
     (Closes: #464047)
+  * Correct combination of upgradeable and allversions options: If a package is
+    not upgradeable, without regard of allversions option nothing gets printed
+    for it.
   * Actualize french manual page.  Thanks, Jean-Baka Domelevo Entfellner.
     (Closes: #460631)
   * Actualize FSF address in a-s-v script.
 
- -- Andreas Hoenen <andreas.hoenen at arcor.de>  Sun, 17 Feb 2008 15:36:59 +0100
+ -- Andreas Hoenen <andreas.hoenen at arcor.de>  Tue, 19 Feb 2008 21:09:17 +0100
 
 apt-show-versions (0.12) unstable; urgency=low
 




More information about the Pkg-asv-commits mailing list