On Sun, Feb 16, 2003 at 01:52:04PM +0100, Daniele Pighin wrote:
> I was thinking of a new option for urpmi (say: "--changes") that would list 
> the changes between the installed version of a package and the most recent 
> available.
> 
> For example, if I had gkrellm-2.1.7a-1mdk installed, and gkrellm-2.1.7a-2mdk 
> was available, typing
> 
> # urpmi --changes gkrellm
> 
> would result in an output similar to
> 
> package gkrellm:
>       2.1.7a-1mdk ==> 2.1.7a-2mdk
>       gkrellmd initscript is back (thanks to Buchan Milne)
> 
> 
> This would allow the user to type something like:
> 
> # urpmi --changes --auto-select
> 
> and get the list of changes for the packages that would be updated by 
> auto-select.
> 
> Thanks for your attention :)

Here's a script that I wrote for this purpose.  Though it doesn't use
the changelogs in hdlist.  Since gc mentioned they are in there maybe I
should go back and figure out how to get them from that file and rewrite
the script.

This is a rough version of the script.  It's on my todo list to finish
it up and fix a few bugs.

Here's some example output.
[EMAIL PROTECTED] breser]# ./updatelist.perl updates
pam-0.75-25.1mdk.i586
pam-devel-0.75-25.1mdk.i586
  * Fri Feb 14 2003 Vincent Danen <[EMAIL PROTECTED]> 0.75-25.1mdk
  
  - security fix for pam_xauth


-- 
Ben Reser <[EMAIL PROTECTED]>
http://ben.reser.org

"America does not go abroad in search of monsters to destroy. She is
the well-wisher to the freedom and independence of all. She is the
champion only of her own." -- John Quincy Adams, July 4th, 1821
#!/usr/bin/perl

use strict;
use warnings;

use urpm;

my $update_source = $ARGV[0];
my $update_url;
my %updates;

my $urpm = new urpm;
$urpm->read_config();

if (!defined($update_source)) {
        die "Didn't enter an update source";
}

foreach my $media (@{$urpm->{media}}) {
  if ($media->{'name'} eq $update_source) {
                $update_url = $media->{'url'};
        }
}

if (!defined($update_url)) {
        die "Unknown source $update_source\n";
}

if ($update_url =~ m#(?:rsync|removeable)://#) {
        die "Sorry we don't support rsync or removeable sources."
}

my $update = `/usr/sbin/urpmi.update $update_source &>1`;
if ($? >> 8) {
        print STDERR "Update command failed with:";
        print STDERR $update;
        die;
}

my $query = `/usr/bin/urpmq -f --media $update_source --auto-select`;
if ($? >> 8) {
        print STDERR "Query command failed with:";
        print STDERR $query;
        die;
}

my (@packages) = split /\s+/, $query;
foreach my $package (@packages) { 
        my $package_url = add_path($update_url,"$package.rpm");
        $package_url =~ s#^file:/##;
        my $rpm_output = `rpm -qp --changelog $package_url`;
        if ($? >> 8) { 
                print STDERR "rpm changelog query failed with:";
                print STDERR $rpm_output;
        } else {
                ($updates{$package}) = $rpm_output =~ /^(\*.*?)\s*^\*/sm;
        }
}

my %reverse_updates;
foreach my $package (keys %updates) {
  if (!defined($reverse_updates{$updates{$package}})) {
    $reverse_updates{$updates{$package}} = [];
  }
  push @{$reverse_updates{$updates{$package}}}, $package;
}

foreach my $changelog (keys %reverse_updates) {
  my $packages = join("\n",sort(@{$reverse_updates{$changelog}}));
  print "$packages\n";
  my (@changelog_lines) = split /\n/, $changelog;
  for my $line (@changelog_lines) {
    print "  $line\n";
  }
  print "\n";
}

# adds a level to a path taking into account if the separator is on the end
# already or not.
sub add_path {
  my ($start_path,$dir_to_add) = @_;

  # Drop any leading slash on $dir_to_add
  $dir_to_add =~ s#^/##;

  if ($start_path =~ m#/$#) {
    $start_path = $start_path . $dir_to_add;
  } else {
    $start_path = "$start_path/$dir_to_add";
  }
  return $start_path;
}


Reply via email to