forked from jan/debianmemberportfolio
Adopt the way which is described in /usr/share/doc/gnupg/DETAILS.gz which expands first line, and use email.utils.parseaddr()
This commit is contained in:
parent
875eb57d35
commit
2752c2e98d
1 changed files with 7 additions and 20 deletions
|
@ -35,6 +35,7 @@ import os.path
|
||||||
import logging
|
import logging
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import email.utils
|
||||||
|
|
||||||
|
|
||||||
def _get_keyrings():
|
def _get_keyrings():
|
||||||
|
@ -58,22 +59,8 @@ def _parse_uid(uid):
|
||||||
Parse a uid of the form 'Real Name <email@example.com>' into email
|
Parse a uid of the form 'Real Name <email@example.com>' into email
|
||||||
and realname parts.
|
and realname parts.
|
||||||
"""
|
"""
|
||||||
uid = uid.strip()
|
(uid, mail) = email.utils.parseaddr(uid)
|
||||||
# First, strip comment
|
return (uid, mail)
|
||||||
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)
|
|
||||||
|
|
||||||
resultdict = {}
|
resultdict = {}
|
||||||
|
|
||||||
|
@ -85,6 +72,7 @@ def _get_canonical(key):
|
||||||
|
|
||||||
|
|
||||||
def _add_to_result(key, newvalue):
|
def _add_to_result(key, newvalue):
|
||||||
|
logging.debug("adding %s: %s", key, newvalue)
|
||||||
thekey = _get_canonical(key)
|
thekey = _get_canonical(key)
|
||||||
if newvalue not in resultdict[thekey]:
|
if newvalue not in resultdict[thekey]:
|
||||||
resultdict[thekey].append(newvalue)
|
resultdict[thekey].append(newvalue)
|
||||||
|
@ -95,10 +83,10 @@ def process_keyrings():
|
||||||
file."""
|
file."""
|
||||||
for keyring in _get_keyrings():
|
for keyring in _get_keyrings():
|
||||||
logging.debug("get data from %s", keyring)
|
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",
|
"--no-expensive-trust-checks",
|
||||||
"--keyring", keyring, "--list-keys",
|
"--keyring", keyring, "--list-keys",
|
||||||
"--with-colons", "--fingerprint"],
|
"--with-colons", "--fixed-list-mode", "--with-fingerprint", "--with-fingerprint"],
|
||||||
stdout=subprocess.PIPE)
|
stdout=subprocess.PIPE)
|
||||||
fpr = None
|
fpr = None
|
||||||
entry = None
|
entry = None
|
||||||
|
@ -108,11 +96,10 @@ def process_keyrings():
|
||||||
uid = None
|
uid = None
|
||||||
if items[0] == 'pub':
|
if items[0] == 'pub':
|
||||||
fpr = entry = None
|
fpr = entry = None
|
||||||
lastpub = items[9].strip()
|
lastpub = items[4].strip()
|
||||||
continue
|
continue
|
||||||
elif items[0] == 'fpr':
|
elif items[0] == 'fpr':
|
||||||
fpr = items[9].strip()
|
fpr = items[9].strip()
|
||||||
uid = lastpub
|
|
||||||
elif items[0] == 'uid':
|
elif items[0] == 'uid':
|
||||||
uid = items[9].strip()
|
uid = items[9].strip()
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue