
########################################################
# Please file all bug reports, patches, and feature
# requests under:
#      https://sourceforge.net/p/logwatch/_list/tickets
# Help requests and discusion can be filed under:
#      https://sourceforge.net/p/logwatch/discussion/
########################################################

#######################################################
## Copyright (c) 2008 Sy Beamont <sbeam@attbi.com>
## Covered under the included MIT/X-Consortium License:
##    http://www.opensource.org/licenses/mit-license.php
## All modifications and contributions by other persons to
## this script are assumed to have been donated to the
## Logwatch project and thus assume the above copyright
## and licensing terms.  If you want to make contributions
## under your own copyright or a different license this
## must be explicitly stated in the contribution an the
## Logwatch project reserves the right to not accept such
## contributions.  If you have made significant
## contributions to this script and want to claim
## copyright please contact logwatch-devel@lists.sourceforge.net.
#########################################################

$Debug = $ENV{'LOGWATCH_DEBUG'} || 0;

if ( $Debug >= 5 ) {
   print STDERR "\n\nDEBUG: Inside dnf-rpm Filter \n\n";
   $DebugCounter = 1;
}

while (defined($ThisLine = <STDIN>)) {
   if ( $Debug >= 5 ) {
      print STDERR "DEBUG($DebugCounter): $ThisLine";
      $DebugCounter++;
   }

   if ( $ThisLine =~ s/^.* (?:INFO|SUBDEBUG) Upgrade: ([^ ]+)/$1/ ) {
      $PackageUpdate{$ThisLine}++;
   } elsif ( $ThisLine =~ s/^.* (?:INFO|SUBDEBUG) Upgraded: ([^ ]+)/$1/ ) {
      $PackageUpdated{$ThisLine}++;
   } elsif ( $ThisLine =~ s/^.* (?:INFO|SUBDEBUG) Installed: ([^ ]+)/$1/ ) {
      $PackageInstalled{$ThisLine}++;
   } elsif ( $ThisLine =~ s/^.* (?:INFO|SUBDEBUG) Reinstalled: ([^ ]+)/$1/ ) {
      $PackageReinstalled{$ThisLine}++;
   } elsif ( $ThisLine =~ s/^.* (?:INFO|SUBDEBUG) Erased?: ([^ ]+)/$1/ ) {
      $PackageErased{$ThisLine}++;
   } elsif ( $ThisLine =~ s/^.* (?:INFO|SUBDEBUG) Obsoleted: ([^ ]+)/$1/ ) {
      $PackageObsoleted{$ThisLine}++;
   } elsif ( $ThisLine =~ s/^.* (?:INFO|SUBDEBUG) Downgrade: ([^ ]+)/$1/ ) {
      $PackageDowngrade{$ThisLine}++;
   } elsif ( $ThisLine =~ s/^.* (?:INFO|SUBDEBUG) Downgraded: ([^ ]+)/$1/ ) {
      $PackageDowngraded{$ThisLine}++;
   } elsif ( $ThisLine =~ m/INFO --- logging initialized ---/ ) {
      $ignoredlines++;
   } elsif ( $ThisLine =~ m/(?:INFO|SUBDEBUG) (Obsolete|Reinstall|Cleanup): / ) {
      $ignoredlines++;
   } elsif ( $ThisLine =~ s/^.* INFO ([^ ]+)/$1/ ) {
      chomp($ThisLine);
      $InfoMessages{$ThisLine}++;
   } else {
      # Report any unmatched entries...
      push @OtherList,$ThisLine;
   }
}

if (keys %PackageInstalled) {
   print "\nPackages Installed:\n";
   foreach $ThisOne (sort {lc($a) cmp lc($b)} keys %PackageInstalled) {
      print "   " . $ThisOne;
   }
}
if (keys %PackageReinstalled) {
   print "\nPackages Reinstalled:\n";
   foreach $ThisOne (sort {lc($a) cmp lc($b)} keys %PackageReinstalled) {
       print "   ". $ThisOne;
   }
}
if (keys %PackageUpdate) {
   print "\nPackages Updated:\n";
   chomp(my @Updated = sort {lc($a) cmp lc($b)} keys %PackageUpdated);
   foreach $ThisOne (sort {lc($a) cmp lc($b)} keys %PackageUpdate) {
       print "   ". shift(@Updated) ." -> ". $ThisOne;
   }
}
if (keys %PackageDowngrade) {
   print "\nPackages Downgraded:\n";
   chomp(my @Downgraded = sort {lc($a) cmp lc($b)} keys %PackageDowngraded);
   foreach $ThisOne (sort {lc($a) cmp lc($b)} keys %PackageDowngrade) {
       print "   ". shift(@Downgraded) ." -> ". $ThisOne;
   }
}
if (keys %PackageErased) {
   print "\nPackages Erased:\n";
   foreach $ThisOne (sort {lc($a) cmp lc($b)} keys %PackageErased) {
       print "   ". $ThisOne;
   }
}
if (keys %PackageObsoleted) {
   print "\nPackages Obsoleted:\n";
   foreach $ThisOne (sort {lc($a) cmp lc($b)} keys %PackageObsoleted) {
       print "   ". $ThisOne;
   }
}

if (keys %InfoMessages) {
   print "\nInformation Messages:\n";
   foreach $ThisOne (sort {$a cmp $b} keys %InfoMessages) {
       print "   ". $ThisOne . ": ". $InfoMessages{$ThisOne} . " Times(s)\n";
   }
}

if ($#OtherList >= 0) {
   print "\n**Unmatched Entries**\n";
   print @OtherList;
}

exit(0);

# vi: shiftwidth=3 tabstop=3 syntax=perl et
# Local Variables:
# mode: perl
# perl-indent-level: 3
# indent-tabs-mode: nil
# End:
