debianmemberportfolio/ddportfolioservice/model/keyfinder.py
Jan Dittberner 1bf24010d5 add tools for handling keyring data
- add model/keyringanalyzer.py inspired by Debian qa's carnivore's
  extract_data
- add model/keyfinder.py using the database built by
  model/keyringanalyzer.py
- store the keyring search directory in model/ddportfolio.ini
2009-01-21 14:39:29 +01:00

49 lines
1.3 KiB
Python

# -*- python -*-
# -*- coding: utf-8 -*-
"""
This module provides tools for finding PGP key information from a
given keyring.
"""
db = None
def _get_keyring_cache():
if db = None:
import anydbm
import pkg_resources
import os.path
filename = pkg_resources.resource_filename(__name__,
'keyringcache')
assert os.path.exists(filename) and os.path.isfile(filename)
db = anydbm.open(filename, 'r')
return db
def _get_cached(cachekey):
cache = _get_keyring_cache()
if cachekey in cache:
return cache[cachekey].split(':')
return None
def getFingerprintByEmail(email):
"""Gets the fingerprints associated with the given email address
if available."""
return _get_cached('fpr:email:%s' % email)
def getRealnameByEmail(email):
"""Gets the real names associated with the given email address if
available."""
return _get_cached('name:email:%s' % email)
def getLoginByEmail(email):
"""Gets the logins associated with the given email address if
available."""
return _get_cached('login:email:%s' % email)
def getLoginByFingerprint(fpr):
"""Gets the login associated with the given fingerprint if
available."""
return _get_cached('login:fpr:%s' % fpr)