[Checkins] SVN: zope.kgs/trunk/src/zope/kgs/ * Use a logger to report events, including errors.

Stephan Richter srichter at cosmos.phy.tufts.edu
Tue Jan 13 22:02:20 EST 2009


Log message for revision 94729:
  * Use a logger to report events, including errors.
  
  * Make output io configurable.
  
  * Handle an error when the XML-RPC call fails.
  

Changed:
  U   zope.kgs/trunk/src/zope/kgs/README.txt
  U   zope.kgs/trunk/src/zope/kgs/change.py

-=-
Modified: zope.kgs/trunk/src/zope/kgs/README.txt
===================================================================
--- zope.kgs/trunk/src/zope/kgs/README.txt	2009-01-13 22:00:38 UTC (rev 94728)
+++ zope.kgs/trunk/src/zope/kgs/README.txt	2009-01-14 03:02:20 UTC (rev 94729)
@@ -362,10 +362,10 @@
 
   >>> from zope.kgs import change
   >>> change.main((cfgFileReal, cfgFileRealOrig))
-  ('PIL', '1.1.6')
-  ('z3c.formdemo', '1.1.0')
-  ('zope.component', '3.4.0')
-  ('zope.interface', '3.4.1')
+  Processing ('PIL', '1.1.6')
+  Processing ('z3c.formdemo', '1.1.0')
+  Processing ('zope.component', '3.4.0')
+  Processing ('zope.interface', '3.4.1')
   ===
   PIL
   ===

Modified: zope.kgs/trunk/src/zope/kgs/change.py
===================================================================
--- zope.kgs/trunk/src/zope/kgs/change.py	2009-01-13 22:00:38 UTC (rev 94728)
+++ zope.kgs/trunk/src/zope/kgs/change.py	2009-01-14 03:02:20 UTC (rev 94729)
@@ -26,10 +26,12 @@
   This is the path to the current controlled packages configuration file.
 
 """
+import logging
 import os
 import pickle
 import re
 import sys
+import xml.parsers.expat
 import xmlrpclib
 import pkg_resources
 import zope.kgs.kgs
@@ -52,6 +54,9 @@
 # decoration_line matches lines to ignore
 decoration_line = re.compile(r"---|===")
 
+# define logger for output
+logger = logging.getLogger('info')
+
 def parseReleases(lines):
     """Parse the list of releases from a CHANGES.txt file.
 
@@ -114,15 +119,27 @@
 
     for package in kgs.packages:
         key = package.name, package.versions[-1]
-        print key
+        logger.info('Processing ' + str(key))
         if key in cache:
             description = cache[key]
         else:
-            data = server.release_data(package.name, package.versions[-1])
+            # Extract release data from server.
+            try:
+                data = server.release_data(package.name, package.versions[-1])
+            except xml.parsers.expat.ExpatError, err:
+                logger.warn('XML-RPC Error: ' + err.message)
+                continue
+
             cache[key] = description = data['description']
-            saveCache('descriptions.dat', cache)
 
-        firstVersion = origVersions.get(package.name, package.versions[0])
+        if description is None:
+            logger.warn('No description found: ' + str(key))
+            continue
+
+        saveCache('descriptions.dat', cache)
+
+        firstVersion = origVersions.get(
+            package.name, package.versions[0])
         lastVersion = package.versions[-1]
         versions = list(
             extractChanges(description, firstVersion, lastVersion))
@@ -131,20 +148,20 @@
     return changes
 
 
-def printChanges(changes):
+def printChanges(changes, output):
     for name, versions in changes:
-        print '=' * len(name)
-        print name
-        print '=' * len(name)
-        print
+        print >> output, '=' * len(name)
+        print >> output, name
+        print >> output, '=' * len(name)
+        print >> output
         for version, release_date, text in versions:
             s = '%s (%s)' % (version, release_date)
-            print s
-            print '-' * len(s)
-            print
-            print text.strip()
-            print
-        print
+            print >> output, s
+            print >> output, '-' * len(s)
+            print >> output, '\n'
+            print >> output, text.strip()
+            print >> output, '\n'
+        print >> output, '\n'
 
 
 def main(args=None):
@@ -155,10 +172,13 @@
         print __file__.__doc__ % sys.argv[0]
         sys.exit(1)
 
+    logger.setLevel(1)
+    logger.addHandler(logging.StreamHandler(sys.stdout))
+
     currentPackageConfigPath = os.path.abspath(args[0])
     origPackageConfigPath = None
     if len(args) > 1:
         origPackageConfigPath = os.path.abspath(args[1])
 
     changes = generateChanges(currentPackageConfigPath, origPackageConfigPath)
-    printChanges(changes)
+    printChanges(changes, sys.stdout)



More information about the Checkins mailing list