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

filippo at alioth.debian.org filippo at alioth.debian.org
Sun Sep 28 12:37:38 UTC 2008


Author: filippo
Date: 2008-09-28 12:37:36 +0000 (Sun, 28 Sep 2008)
New Revision: 1307

Modified:
   upload-history/munge_ddc.py
Log:
some refactoring

Modified: upload-history/munge_ddc.py
===================================================================
--- upload-history/munge_ddc.py	2008-09-28 07:32:12 UTC (rev 1306)
+++ upload-history/munge_ddc.py	2008-09-28 12:37:36 UTC (rev 1307)
@@ -27,45 +27,49 @@
 
 bugnumber_list_RE = re.compile("^([0-9]{3,} ?)+")
 
-def extract_pgp(msg, keyring=["/usr/share/keyrings/debian-keyring.gpg",
+def get_key_info_gpgv(msg, keyring=["./debian-keyring.gpg",
+                              "./debian-maintainers.gpg",
+                              "/usr/share/keyrings/debian-keyring.gpg",
                               "/usr/share/keyrings/debian-maintainers.gpg",
-                              "./debian-keyring.gpg",
-                              "./debian-maintainers.gpg"]):
+                              ]):
     """ Verify given msg with gpgv using the given (list of) keyring(s)
     
     Return a tuple (key, key-id) or ("N/A", "N/A") if key not available"""
 
-    opts = ["/usr/bin/gpgv", "--status-fd", "1"]
+    cmd = ["/usr/bin/gpgv", "--status-fd", "1"]
 
-    keyrings = []
+    opt_keyrings = []
     if isinstance(keyring, str):
         if os.path.exists(keyring):
-            keyrings.extend(["--keyring", keyring])
+            opt_keyrings.extend(["--keyring", keyring])
     else:
         for k in tuple(keyring):
             if os.path.exists(str(k)):
-                keyrings.extend(["--keyring", str(k)])
+                opt_keyrings.extend(["--keyring", str(k)])
 
-    if keyrings:
-        opts.extend(keyrings)
+    if opt_keyrings:
+        cmd.extend(opt_keyrings)
     else:
+        # XXX raise exception?
         return ("N/A", "N/A")
 
-    p = subprocess.Popen(opts, stdin=subprocess.PIPE, stderr=subprocess.PIPE,
+    p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stderr=subprocess.PIPE,
             stdout=subprocess.PIPE, env={"LC_ALL": "C"} )
 
     (out, err) = p.communicate("\n".join(msg))
-    
+   
     m = keyid_RE.search(out)
     if m:
         #sys.stderr.write(m.group(2))
         if m.group(1) == "GOOD":
-            return m.group(2), m.group(3)
+            return (m.group(2), m.group(3))
         else:
-            return m.group(2), "N/A"
+            return (m.group(2), "N/A")
     else:
         return ("N/A", "N/A")
 
+get_key_info = get_key_info_gpgv
+
 def normalize_date(date):
     d = emailutils.parsedate_tz(date)
     if not d:
@@ -80,7 +84,7 @@
 
 # XXX factor this to work with plain .changes
 def munge_ddc(mb_file, outfile=sys.stdout):
-    """ Scan given mb_file as a unix mailbox and extract upload informations """
+    """ Scan given filename mb_file as a unix mailbox and extract upload informations """
 
     mb = mailbox.PortableUnixMailbox(file(mb_file), factory=email.message_from_file)
 
@@ -103,7 +107,7 @@
         
         body = msg.get_payload(decode=True).split('\n')
         
-# XXX work around Hash: sha1(\n)+ at the beginning of signed body
+        # XXX work around Hash: sha1(\n)+ at the beginning of signed body
         for (i,l) in enumerate(body):
             if l.startswith("Format:"):
                 break
@@ -128,7 +132,7 @@
         
         c['NMU'] = ((nmu_version is not None) and (nmu_changes is not None))
 
-        (c['Key'], c['Signed-By']) = extract_pgp(body)
+        (c['Key'], c['Signed-By']) = get_key_info(body)
 
         ### Fields sanitization
 
@@ -153,6 +157,8 @@
                 outfile.write("%s: %s" % (field, str(c[field]).strip('\n')))
             except KeyError:
                 outfile.write("%s: N/A" % field)
+            # separate different fields
+            outfile.write("\n")
 
         # separate different packages
         outfile.write("\n")




More information about the Collab-qa-commits mailing list