[Collab-qa-commits] r618 - upload-history

filippo at alioth.debian.org filippo at alioth.debian.org
Thu Dec 27 14:24:58 UTC 2007


Author: filippo
Date: 2007-12-27 14:24:58 +0000 (Thu, 27 Dec 2007)
New Revision: 618

Modified:
   upload-history/mbox_to_csv.py
Log:
improve error reporting and robustness

Modified: upload-history/mbox_to_csv.py
===================================================================
--- upload-history/mbox_to_csv.py	2007-12-27 12:03:48 UTC (rev 617)
+++ upload-history/mbox_to_csv.py	2007-12-27 14:24:58 UTC (rev 618)
@@ -18,34 +18,41 @@
     mb = mailbox.PortableUnixMailbox(file(mb_file), factory=email.message_from_file)
 
     for msg in mb:
-        assert msg.is_multipart() == False
+        if msg.is_multipart():
+            continue
         
         body = msg.get_payload().split('\n')
 
         is_nmu = False
         c = deb822.Changes(body)
         
-        print "processing: " + c['Source']
+        try:
+            sys.stdout.write("processing: " + c['Source'] + "\n")
+        except KeyError:
+            print "unable to find source"
+            continue
 
+        pkg = c['Source']
+ 
         try:
             if not 'source' in c['Architecture']:
-                print "  source not in architecture"
+                sys.stderr.write("%s: source not in architecture\n" % pkg)
                 continue
         except KeyError:
-            print "  source not in architecture"
+            sys.stderr.write("%s: architecture not found\n" % pkg)
             continue
         
         try:
-           nmu_version = nmu_version_RE.search(c['Version'])
+            nmu_version = nmu_version_RE.search(c['Version'])
         except KeyError:
-           print "  no version"
-           continue
+            sys.stderr.write("%s: version not found\n" % pkg)
+            continue
 
         try:
            nmu_changes = nmu_changelog_RE.search(c['Changes'])
         except KeyError:
-           print "  no changes"
-           pass
+            sys.stderr.write("%s: changes not found\n" % pkg)
+            pass
         #   logfile.write(fname + " no changes NMU not detected\n")
         
         is_nmu = ((nmu_version is not None) and (nmu_changes is not None))
@@ -53,8 +60,11 @@
         try:
             unixtime = int(rfc822.mktime_tz(rfc822.parsedate_tz(c['Date'])))
         except KeyError:
-            print "  no date"
+            sys.stderr.write("%s: date not found\n" % pkg)
             continue
+        except TypeError:
+            sys.stderr.write("%s: date not parsable\n" % pkg)
+            continue
 
         if not c.has_key('Changed-By'):
             c['Changed-By'] = ""
@@ -62,7 +72,7 @@
         try:
             outfile.write("%s|%s|%s|%s|%s|%s\n" % (c['Source'], c['Version'], unixtime, c['Maintainer'], c['Changed-By'], is_nmu))
         except KeyError:
-            print "  not printing"
+            sys.stderr.write("%s: error printing\n" % pkg)
             continue
 
 if __name__ == '__main__':




More information about the Collab-qa-commits mailing list