The default output of repodiff, even with the --simple command line option 
isn't all that easy to script around.
Some enhancement is needed.  This patch adds the --csv option.  It doesn't 
output the summary or any extras and
it produces very simple output:
oldpkg-name-ver-rel,newpkg-name-ver-rel

When a package is new, the first field will be empty as there would have been 
no old package.
When a package is removed, the second field will be empty unless a package 
obsoleting it exists.


Cheers...Paul...


diff -ur yum-utils-1.1.28.orig/repodiff.py yum-utils-1.1.28/repodiff.py
--- yum-utils-1.1.28.orig/repodiff.py   2010-08-03 10:56:48.000000000 -0500
+++ yum-utils-1.1.28/repodiff.py        2011-01-17 18:11:29.164953595 -0600
@@ -151,6 +151,8 @@
                       help="Output size changes for any new->old packages")
     parser.add_option("--simple",  default=False, action='store_true',
                       help="output simple format")
+    parser.add_option("--csv",  default=False, action='store_true',
+                      help="output comma separated value format")
     (opts, argsleft) = parser.parse_args()
 
     if not opts.new or not opts.old:
@@ -204,19 +206,30 @@
     remove_sizechange = 0
     if ygh.add:
         for pkg in sorted(ygh.add):
-            print 'New package: %s-%s-%s' % (pkg.name, pkg.ver, pkg.rel)
-            print '             %s\n' % to_unicode(pkg.summary)
+            if opts.csv and not opts.simple:
+                print ',%s-%s-%s' % (pkg.name, pkg.ver, pkg.rel)
+            else:
+                print 'New package: %s-%s-%s' % (pkg.name, pkg.ver, pkg.rel)
+                print '             %s\n' % to_unicode(pkg.summary)
             add_sizechange += int(pkg.size)
                 
     if ygh.remove:
         for pkg in sorted(ygh.remove):
-            print 'Removed package:  %s-%s-%s' % (pkg.name, pkg.ver, pkg.rel)
+            if opts.csv and not opts.simple:
+                msg = '%s-%s-%s,' % (pkg.name, pkg.ver, pkg.rel)
+            else:
+                print 'Removed package:  %s-%s-%s' % (pkg.name, pkg.ver, 
pkg.rel)
             if pkg in ygh.obsoleted:
-                print 'Obsoleted by   :  %s' % ygh.obsoleted[pkg]
+                if opts.csv and not opts.simple:
+                    msg += '%s-%s-%s' % (ygh.obsoleted[pkg].name, 
ygh.obsoleted[pkg].ver, ygh.obsoleted[pkg].rel)
+                else:
+                    print 'Obsoleted by   :  %s' % ygh.obsoleted[pkg]
+            print msg
             remove_sizechange += (int(pkg.size))
                 
     if ygh.modified:
-        print '\nUpdated Packages:\n'
+        if not opts.csv:
+            print '\nUpdated Packages:\n'
         for (pkg, oldpkg) in sorted(ygh.modified):
             if opts.size:
                 sizechange = int(pkg.size) - int(oldpkg.size)
@@ -225,6 +238,9 @@
             if opts.simple:
                 msg = "%s: %s-%s-%s ->  %s-%s-%s" % (pkg.name, oldpkg.name, 
                         oldpkg.ver, oldpkg.rel, pkg.name, pkg.ver, pkg.rel)
+            elif opts.csv:
+                msg = "%s-%s-%s,%s-%s-%s" % (oldpkg.name, 
+                        oldpkg.ver, oldpkg.rel, pkg.name, pkg.ver, pkg.rel)
             else:
                 msg = "%s-%s-%s" % (pkg.name, pkg.ver, pkg.rel)
                 dashes = "-" * len(msg) 
@@ -258,14 +274,15 @@
         not my.pkgSack.searchNevra(arch='src')):
         print "** No 'src' pkgs in any repo. maybe see docs. on --archlist?"
 
-    print '\nSummary:'
-    print 'Added Packages: %s' % len(ygh.add)
-    print 'Removed Packages: %s' % len(ygh.remove)
-    print 'Modified Packages: %s' % len(ygh.modified)
-    if opts.size:
-        print 'Size of added packages: %s' % add_sizechange
-        print 'Size change of modified packages: %s' % total_sizechange
-        print 'Size of removed packages: %s' % remove_sizechange
+    if not opts.csv:
+        print '\nSummary:'
+        print 'Added Packages: %s' % len(ygh.add)
+        print 'Removed Packages: %s' % len(ygh.remove)
+        print 'Modified Packages: %s' % len(ygh.modified)
+        if opts.size:
+            print 'Size of added packages: %s' % add_sizechange
+            print 'Size change of modified packages: %s' % total_sizechange
+            print 'Size of removed packages: %s' % remove_sizechange
     
       
 if __name__ == "__main__":




-- 
---
Paul B Schroeder
<paulbsch "at" vbridges "dot" com>
_______________________________________________
Yum-devel mailing list
[email protected]
http://lists.baseurl.org/mailman/listinfo/yum-devel

Reply via email to