Wednesday, December 14, 2011

OpenSUSE Changelogs for Recent Updates

Here is a short python script that shows recent portions of the changelogs for recently installed packages. This script is indented for extracting a summary of what has changed after updating my OS to latest packages. Usage is as follows:
% python -h
Usage: [options]

Report change log entries for recent installs (zypper/rpm).

  -h, --help            show this help message and exit
  -i INSTALLDAYS, --installed-since=INSTALLDAYS
                        Include anything installed up to INSTALLDAYS days ago.
  -c CHANGEDAYS, --changedSince=CHANGEDAYS
                        Report change log entries from up to CHANGEDAYS days

Sample output:
python -i 1 -c 30
+Package:  2011-12-14 21:11:12 glibc
* Wed Nov 30 2011
- Do not install INSTALL file.

* Wed Nov 30 2011
- fix printf with many args and printf arg specifiers (bnc#733140)

* Fri Nov 25 2011
- Updated glibc-ports-2.14.1.tar.bz2 from

* Fri Nov 25 2011
- Create glibc-devel-static baselibs (bnc#732349).

* Fri Nov 18 2011
- Remove duplicated locales from glibc-2.3.locales.diff.bz2

+Package:  2011-12-14 21:11:21 splashy
* Thu Dec 08 2011
- update artwork for openSUSE 12.1 (bnc#730050)

+Package:  2011-12-14 21:11:23 libqt4
* Wed Nov 23 2011
- do not assert on QPixmap usage in non-GUI threads
  if XInitThreads() has been called (bnc#731455)

+Package:  2011-12-14 21:11:23 libcolord1
* Wed Dec 07 2011
- Update to version 0.1.15:
  + This release fixes an important security bug: CVE-2011-4349.
  + New Features:
  - Add a native driver for the Hughski ColorHug hardware
  - Export cd-math as three projects are now using it
  + Bugfixes:
  - Documentation fixes and improvements
  - Do not crash the daemon if adding the device to the db failed
  - Do not match any sensor device with a kernel driver
  - Don't be obscure when the user passes a device-id to colormgr
  - Fix a memory leak when getting properties from a device
  - Fix colormgr device-get-default-profile


The script produces a summary by extracting a list of recent installs from /var/log/zypp/history. For each recent install the script issues an rpm changelog query to obtain each package's changelog. Each changelog is written out line by line and the output is truncated when a date is encountered that is more than the specified number of days in the past.

The code

#!/usr/bin/env python
# Copyright (C) 2011: Michael Hamilton
# The code is GPL 3.0(GNU General Public License) ( )
import csv
import subprocess
from datetime import date, datetime,  timedelta
from optparse import OptionParser

zyppHistFilename = '/var/log/zypp/history'

optParser = OptionParser(description='Report change log entries for recent installs (zypper/rpm).')
optParser.add_option('-i',  '--installed-since',  dest='INSTALLDAYS', type='int', default=1,  help='Include anything installed up to INSTALLDAYS days ago.')
optParser.add_option('-c',  '--changedSince',  dest='CHANGEDAYS', type='int', default=60,  help='Report change log entries from up to CHANGEDAYS days ago.')
(options, args) = optParser.parse_args()

installedSince = - timedelta(days=options.INSTALLDAYS)
changedSince = - timedelta(days=options.CHANGEDAYS)

zyppHistReader = csv.reader(open(zyppHistFilename, 'rb'), delimiter='|')
for historyRec in zyppHistReader:
    if historyRec[0][0] != '#' and historyRec[1] == 'install':
        installDate = datetime.strptime(historyRec[0], '%Y-%m-%d %H:%M:%S')
        if installDate >= installedSince:
            packageName = historyRec[2]
            print '=================================================='
            print '+Package: ',  installDate, packageName
            print '------------------------------'
            rpmProcess = subprocess.Popen(['rpm', '-q', '--changelog',  packageName], shell=False, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
            if rpmProcess.returncode != 0:
                print '*** ERROR (return code was ', rpmProcess.returncode,  ')'
            for line in rpmProcess.stderr:
                print line, 
            for line in rpmProcess.stdout:
                    if line[0] == '*' and line[1] == ' ' and len(line) > 17:
                        changeDate = datetime.strptime(line[6:17], '%b %d %Y')
                        if changeDate < changedSince:
                except ValueError:
                    pass # not a date - move on
                print line, 

No comments:

Post a Comment

These days we're only getting spam, so comments are now disabled.

Note: Only a member of this blog may post a comment.