From 2752c2e98d6d0ab7c6420ddd7a0275f0dabad342 Mon Sep 17 00:00:00 2001 From: Olivier Berger Date: Fri, 15 Nov 2013 14:31:46 +0100 Subject: [PATCH] Adopt the way which is described in /usr/share/doc/gnupg/DETAILS.gz which expands first line, and use email.utils.parseaddr() --- ddportfolioservice/model/keyringanalyzer.py | 27 ++++++--------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/ddportfolioservice/model/keyringanalyzer.py b/ddportfolioservice/model/keyringanalyzer.py index cc501c6..b3304a7 100644 --- a/ddportfolioservice/model/keyringanalyzer.py +++ b/ddportfolioservice/model/keyringanalyzer.py @@ -35,6 +35,7 @@ import os.path import logging import subprocess import sys +import email.utils def _get_keyrings(): @@ -58,22 +59,8 @@ def _parse_uid(uid): Parse a uid of the form 'Real Name ' into email and realname parts. """ - uid = uid.strip() - # First, strip comment - s = uid.find('(') - e = uid.find(')') - if s >= 0 and e >= 0: - uid = uid[:s] + uid[e + 1:] - s = uid.find('<') - e = uid.find('>') - email = None - if s >= 0 and e >= 0: - email = uid[s + 1:e] - uid = uid[:s] + uid[e + 1:] - uid = uid.strip() - if not email and uid.find('@') >= 0: - email, uid = uid, email - return (uid, email) + (uid, mail) = email.utils.parseaddr(uid) + return (uid, mail) resultdict = {} @@ -85,6 +72,7 @@ def _get_canonical(key): def _add_to_result(key, newvalue): + logging.debug("adding %s: %s", key, newvalue) thekey = _get_canonical(key) if newvalue not in resultdict[thekey]: resultdict[thekey].append(newvalue) @@ -95,10 +83,10 @@ def process_keyrings(): file.""" for keyring in _get_keyrings(): logging.debug("get data from %s", keyring) - proc = subprocess.Popen(["gpg", "--no-default-keyring", + proc = subprocess.Popen(["gpg", "--no-options", "--no-default-keyring", "--no-expensive-trust-checks", "--keyring", keyring, "--list-keys", - "--with-colons", "--fingerprint"], + "--with-colons", "--fixed-list-mode", "--with-fingerprint", "--with-fingerprint"], stdout=subprocess.PIPE) fpr = None entry = None @@ -108,11 +96,10 @@ def process_keyrings(): uid = None if items[0] == 'pub': fpr = entry = None - lastpub = items[9].strip() + lastpub = items[4].strip() continue elif items[0] == 'fpr': fpr = items[9].strip() - uid = lastpub elif items[0] == 'uid': uid = items[9].strip() else: