[Collab-qa-commits] r896 - upload-history
filippo at alioth.debian.org
filippo at alioth.debian.org
Tue Jun 24 17:59:27 UTC 2008
Author: filippo
Date: 2008-06-24 17:59:26 +0000 (Tue, 24 Jun 2008)
New Revision: 896
Added:
upload-history/munge_ddc.py
Log:
munge upload information from d-d-c mailbox into rfc822 file
Added: upload-history/munge_ddc.py
===================================================================
--- upload-history/munge_ddc.py (rev 0)
+++ upload-history/munge_ddc.py 2008-06-24 17:59:26 UTC (rev 896)
@@ -0,0 +1,116 @@
+#!/usr/bin/python2.4
+# extract upload info from a debian-devel-changes mailbox file
+
+import email
+import mailbox
+import re
+import rfc822
+import subprocess
+import sys
+import os
+
+from debian_bundle import deb822
+
+# XXX gives false positives for example with -x+y.z.w, mitigated by checking Changes also
+# XXX might change in the future, see DEP1 http://wiki.debian.org/NmuDep
+nmu_version_RE = re.compile("(-\S+\.\d+|\+nmu\d+)$")
+nmu_changelog_RE = re.compile("\s+\*\s+.*(NMU|non[- ]maintainer)", re.IGNORECASE + re.MULTILINE)
+
+#keyid_RE = re.compile("Signature made (.+) using \S+ key ID (\S+)")
+keyid_RE = re.compile("\[GNUPG:\] (GOOD|BAD|ERR)SIG (\S+) (.+)")
+
+def extract_pgp(msg, keyring=["/usr/share/keyrings/debian-keyring.gpg",
+ "/usr/share/keyrings/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"]
+
+ keyrings = []
+ if isinstance(keyring, str):
+ if os.path.exists(keyring):
+ keyrings.extend(["--keyring", keyring])
+ else:
+ for k in tuple(keyring):
+ if os.path.exists(str(k)):
+ keyrings.extend(["--keyring", str(k)])
+
+ if keyrings:
+ opts.extend(keyrings)
+ else:
+ return ("N/A", "N/A")
+
+ p = subprocess.Popen(opts, stdin=subprocess.PIPE, stderr=subprocess.PIPE,
+ stdout=subprocess.PIPE)
+
+ (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)
+ else:
+ return m.group(2), "N/A"
+ else:
+ return ("N/A", "N/A")
+
+# 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 """
+
+ #outfile = file(mb_file + ".csv", 'w')
+
+ mb = mailbox.PortableUnixMailbox(file(mb_file), factory=email.message_from_file)
+
+ for msg in mb:
+ if msg.is_multipart():
+ continue
+ body = msg.get_payload(decode=True).split('\n')
+
+# XXX work around Hash: sha1(\n)+ at the beginning of signed body
+ for (i,l) in enumerate(body):
+ if l.startswith("Format:"):
+ break
+
+ c = deb822.Changes(body[i:])
+
+ required = set(['Source', 'Architecture', 'Version', 'Changes'])
+ found = set(c.keys())
+
+ if not required.issubset(found):
+ sys.stderr.write("%s %s fields not found: %s\n" % (mb_file, msg['Subject'], " ".join(required.difference(found))))
+ sys.stderr.write("%s" % "\n".join(c))
+ continue
+
+ if not 'source' in c['Architecture']:
+ #sys.stderr.write("%s: source not in architecture\n" % pkg)
+ continue
+
+ nmu_version = nmu_version_RE.search(c['Version'])
+ nmu_changes = nmu_changelog_RE.search(c['Changes'])
+
+ c['NMU'] = ((nmu_version is not None) and (nmu_changes is not None))
+
+ (c['Key'], c['Key-UID']) = extract_pgp(body)
+
+ for field in 'Source', 'Version', 'Date', 'Changed-By', 'Maintainer', 'NMU', 'Key', 'Key-UID':
+ try:
+ print "%s: %s" % (field, c[field])
+ except KeyError:
+ print "%s: N/A" % field
+
+ # separate different packages
+ print
+
+
+if __name__ == '__main__':
+ if len(sys.argv) < 2:
+ print "usage: file1 .. fileN"
+ sys.exit(1)
+
+ for f in sys.argv[1:]:
+ munge_ddc(f)
+
+# vim: et:ts=4:sw=4
Property changes on: upload-history/munge_ddc.py
___________________________________________________________________
Name: svn:executable
+ *
More information about the Collab-qa-commits
mailing list