[csw-devel] SF.net SVN: opencsw:[357] buildfarm/bin

dmichelsen at users.sourceforge.net dmichelsen at users.sourceforge.net
Fri Mar 11 11:33:28 CET 2011


Revision: 357
          http://opencsw.svn.sourceforge.net/opencsw/?rev=357&view=rev
Author:   dmichelsen
Date:     2011-03-11 10:33:27 +0000 (Fri, 11 Mar 2011)

Log Message:
-----------
cswrepo: Some more work

Modified Paths:
--------------
    buildfarm/bin/cswrepo

Added Paths:
-----------
    buildfarm/bin/CSW/
    buildfarm/bin/CSW/Catalog.pm

Added: buildfarm/bin/CSW/Catalog.pm
===================================================================
--- buildfarm/bin/CSW/Catalog.pm	                        (rev 0)
+++ buildfarm/bin/CSW/Catalog.pm	2011-03-11 10:33:27 UTC (rev 357)
@@ -0,0 +1,178 @@
+package CSW::Catalog;
+
+sub new {
+  my ($class,$catalogfile) = @_;
+
+  my %catalog;
+
+  open F, $catalogfile or die "Cannot open $catalogfile";
+  while( <F> ) {
+    # 9menu 1.8,REV=2006.05.19 CSW9menu 9menu-1.8,REV=2006.05.19-SunOS5.8-i386-CSW.pkg.gz 51eaeee15a71a4290789729feb956759 12196 CSWcommon non
+
+    last if( /^-----BEGIN PGP SIGNATURE-----/ );
+    next if( /^(----.*|Hash:.*|#.*|)$/ );
+
+    chomp;
+    my @fields = split(/\s+/);
+    if( @fields < 5 || @fields > 9 ) {
+      print "ERROR: ", scalar( @fields ), " $_\n";
+      next;
+    }
+    
+    my ($cname,$version,$pkgname,$pkgfile,$md5,$size,$deps,$ideps,$category) = split(/\s+/);
+    $catalog{$cname} = {
+	catalogname => $cname,
+	version => $version,
+	pkgname => $pkgname,
+	pkgfile => $pkgfile,
+	md5 => $md5,
+	size => $size,
+	deps => ($deps eq 'none' ? [] : [ sort split( /\|/, $deps ) ]),
+	ideps => ($ideps eq 'none' ? [] : [ sort split( /\|/, $ideps ) ]),
+    };
+  }
+  close F;
+
+  return bless \%catalog, ref( $class ) || $class;
+}
+
+sub _equal {
+  my ($e1, $e2) = @_;
+  return ($e1->{version} eq $e2->{version} &&
+	$e1->{pkgname} eq $e2->{pkgname} &&
+	$e1->{pkgfile} eq $e2->{pkgfile} &&
+	$e1->{md5} eq $e2->{md5} &&
+	$e1->{size} eq $e2->{size} &&
+	join('|', @{$e1->{deps}}) eq join('|', @{$e2->{deps}}) &&
+	join('|', @{$e1->{ideps}}) eq join('|', @{$e2->{ideps}})
+	);
+}
+
+sub _depcompare {
+  my ($a1, $a2) = @_;
+
+  my %a1;
+  my (@additions, at removals);
+  foreach my $a1 (@$a1) {
+    $a1{$a1} = 1;
+  }
+  foreach my $a2 (@$a2) {
+    if( exists $a1{$a2} ) {
+      delete $a1{$a2};
+    } else {
+      push @additions, $a2;
+    }
+  }
+  @removals = keys %a1;
+  return [\@removals,\@additions];
+}
+
+sub _extract_version {
+  my ($v) = @_;
+  $v =~ s/,REV=\d{4}\.\d{2}\.\d{2}//;
+  return $v;
+}
+
+sub _eq_version {
+  # 2009.09.09,REV=2009.09.09
+  my ($v1,$v2) = @_;
+  $v1 = _extract_version( $v1 );
+  $v2 = _extract_version( $v2 );
+
+  return $v1 eq $v2;
+}
+
+sub _compare_rev {
+  # 2009.09.09,REV=2009.09.09
+  my ($v1,$v2) = @_;
+
+  my ($y1,$m1,$d1) = ($v1 =~ /,REV=(\d{4})\.(\d{2})\.(\d{2})/);
+  my ($y2,$m2,$d2) = ($v2 =~ /,REV=(\d{4})\.(\d{2})\.(\d{2})/);
+
+  if( !defined $y1 || !defined $m1 || !defined $d1 ) {
+    return 0 if( !defined $y2 || !defined $m2 || !defined $d2 );
+    return 1;
+  }
+  return -1 if( !defined $y2 || !defined $m2 || !defined $d2 );
+
+  return ($y1 cmp $y2)*4 + ($m1 cmp $m2)*2 + ($d1 cmp $d2);
+}
+
+sub compare {
+  my ($co1, $co2) = @_;
+  my %c1 = %$co1;
+  my %c2 = %$co2;
+
+  my %hchanges;
+
+  my (%pc1, %pc2);
+  $pc1{$_->{pkgname}} = $_ foreach (values %c1);
+  $pc2{$_->{pkgname}} = $_ foreach (values %c2);
+
+  # 1. Find differences in attributes for packages with same catalog name
+  #    (additions, updates, removals)
+  foreach my $p1 (keys %c1) {
+    if( exists( $c2{$p1} ) ) {
+      # Entries with same catalog name exist in catalog 1 and 2
+      if( !_equal( $c1{$p1}, $c2{$p1} ) ) {
+        # Package as been updated
+        $hchanges{$p1}->{_pkgname} = $c1{$p1}->{pkgname};
+        my %e1 = %{$c1{$p1}};
+        my %e2 = %{$c2{$p1}};
+	my $versiondiff = $e1{version} ne $e2{version};
+	my $pkgnamediff = $e1{pkgname} ne $e2{pkgname};
+	my $pkgfilediff = $e1{pkgfile} ne $e2{pkgfile};
+	my $md5diff = $e1{md5} ne $e2{md5};
+	my $sizediff = $e1{size} ne $e2{size};
+        if( $versiondiff ) {
+          my ($v1,$v2) = ($e1{version}, $e2{version});
+          if( _eq_version( $v1, $v2 ) ) {
+            $hchanges{$p1}->{version} = { type => "Respin", from => $e1{version}, to => $e2{version} };
+          } elsif( _compare_rev( $v1, $v2 ) ) {
+            $hchanges{$p1}->{version} = { type => "Update", from => $e1{version}, to => $e2{version} };
+          } else {
+            $hchanges{$p1}->{version} = { type => "Sameday update", from => $e1{version}, to => $e2{version} };
+          }
+        } else {
+	  # If the version has been updated we have another package, so differences on the other fields are pretty obvious
+          $hchanges{$p1}->{pkgname} = { type => "Changed", from => $e1{pkgname}, to => $e2{pkgname} } if( $pkgnamediff );
+          $hchanges{$p1}->{pkgfile} = { type => "Changed", from => $e1{pkgfile}, to => $e2{pkgfile} } if( $pkgfilediff );
+          $hchanges{$p1}->{md5} = { type => "Changed", from => $e1{md5}, to => $e2{md5} } if( $md5diff );
+          $hchanges{$p1}->{size} = { type => "Changed", from => $e1{size}, to => $e2{size} } if( $sizediff );
+	}
+        my $dep = _depcompare( $e1{deps}, $e2{deps} );
+        if( @{$dep->[0]} > 0 || @{$dep->[1]} > 0 ) {
+          $hchanges{$p1}->{deps} = { type => "Changed", removed => $dep->[0], added => $dep->[1] };
+	}
+        my $idep = _depcompare( $e1{ideps}, $e2{ideps} );
+        if( @{$idep->[0]} > 0 || @{$idep->[1]} > 0 ) {
+          $hchanges{$p1}->{ideps} = { type => "Changed", removed => $idep->[0], added => $idep->[1] };
+        }
+      } else {
+        # Package is same, ignore.
+      }
+      delete $c2{$p1};
+    } else {
+      # Catalogname is in catalog 1 only, deletion
+      my $pkgname = $c1{$p1}->{pkgname};
+      $hchanges{$p1}->{_pkgname} = $pkgname;
+      if( exists $pc2{$pkgname} && $pc2{$pkgname}->{catalogname} ne $c1{$p1}->{catalogname} ) {
+        $hchanges{$p1}->{catalogname} = { type => "Changed", from => $c1{$p1}->{catalogname}, to => $pc2{$pkgname}->{catalogname} };
+        # If it was a rename we processed it, so remove it here
+        delete $c2{$pc2{$pkgname}->{catalogname}};
+      } else {
+        $hchanges{$p1}->{package} = { type => "Deleted", pkg => $c1{$p1}->{pkgname} };
+      }
+    }
+  }
+
+  # What is left in catalog 2 are additions
+  foreach my $p2 (keys %c2) {
+    $hchanges{$p2}->{_pkgname} = $c2{$p2}->{pkgname};
+    $hchanges{$p2}->{package} = { type => "Added", pkg => $c2{$p2}->{pkgname} };
+  }
+
+  return \%hchanges;
+}
+
+1;


Property changes on: buildfarm/bin/CSW/Catalog.pm
___________________________________________________________________
Added: svn:executable
   + *

Modified: buildfarm/bin/cswrepo
===================================================================
--- buildfarm/bin/cswrepo	2011-03-11 10:32:41 UTC (rev 356)
+++ buildfarm/bin/cswrepo	2011-03-11 10:33:27 UTC (rev 357)
@@ -217,18 +217,22 @@
 
 sub compare {
   my ($co1, $co2) = @_;
-  my %c1 = %$co1;
-  my %c2 = %$co2;
 
+  my @c1 = $co1->entries();
+  my @c2 = $co2->entries();
+
   my %hchanges;
 
   my (%pc1, %pc2);
-  $pc1{$_->{pkgname}} = $_ foreach (values %c1);
-  $pc2{$_->{pkgname}} = $_ foreach (values %c2);
+  $pc1{$_->{pkgname}} = $_ foreach (@c1);
+  $pc2{$_->{pkgname}} = $_ foreach (@c2);
 
   # 1. Find differences in attributes for packages with same catalog name
   #    (additions, updates, removals)
-  foreach my $p1 (keys %c1) {
+  foreach my $po1 (@c1) {
+use Data::Dumper;
+print Dumper( $po1 );
+    my $p1 = $po1->catalogname;
     if( exists( $c2{$p1} ) ) {
       # Entries with same catalog name exist in catalog 1 and 2
       if( !_equal( $c1{$p1}, $c2{$p1} ) ) {
@@ -284,7 +288,8 @@
   }
 
   # What is left in catalog 2 are additions
-  foreach my $p2 (keys %c2) {
+  foreach my $po2 (keys %c2) {
+    my $p2 = $po2->catalogname;
     $hchanges{$p2}->{_pkgname} = $c2{$p2}->{pkgname};
     $hchanges{$p2}->{package} = { type => "Added", pkg => $c2{$p2}->{pkgname} };
   }
@@ -749,11 +754,14 @@
 }
 
 sub diff {
-  my ($name, $c1, $c2) = @ARGV;
+  my ($c1, $c2) = @ARGV;
 
   my $cf1 = CSW::Catalog->new( $c1 );
   my $cf2 = CSW::Catalog->new( $c2 );
 
+  #my %hchanges = %{$cf1->compare( $cf2 )};
+use Data::Dumper;
+  #print Dumper( $cf1->compare( $cf2 )) ;
   my %hchanges = %{$cf1->compare( $cf2 )};
 
   my ($npackageadded, $npackagedeleted, $nversion, $npkgname, $npkgfile, $nmd5, $nsize, $ndeps, $nideps) = (0,0,0,0,0,0,0,0,0);
@@ -772,8 +780,6 @@
   }
 
   print <<EOF;
-These are the differences to $name.
-
                       Packages added: $npackageadded
                     Packages deleted: $npackagedeleted
                      Version updates: $nversion


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


More information about the devel mailing list