forked from jan/debianmemberportfolio
add logging and make keyringanalyzer work on Squeeze
- add logging to ddportfolioservice/model/keyfinder.py and ddportfolioservice/model/keyringanalyzer.py - use ~ instead of ${HOME} in ddportfolioservice/model/ddportfolio.ini - use subprocess.Popen instead of os.popen
This commit is contained in:
parent
fac0c223f4
commit
9af353765d
3 changed files with 26 additions and 10 deletions
|
@ -19,7 +19,7 @@
|
||||||
# <http://www.gnu.org/licenses/>.
|
# <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
keyring.dir=${HOME}/debian/keyring.debian.org/keyrings
|
keyring.dir=~/debian/keyring.debian.org/keyrings
|
||||||
urlbuilder.sections=overview,bugs,build,qa,upload,lists,files,membership,
|
urlbuilder.sections=overview,bugs,build,qa,upload,lists,files,membership,
|
||||||
miscellaneous,ssh,ubuntu
|
miscellaneous,ssh,ubuntu
|
||||||
|
|
||||||
|
|
|
@ -24,24 +24,31 @@
|
||||||
This module provides tools for finding PGP key information from a
|
This module provides tools for finding PGP key information from a
|
||||||
given keyring.
|
given keyring.
|
||||||
"""
|
"""
|
||||||
|
import logging
|
||||||
|
import time
|
||||||
|
|
||||||
db = None
|
db = None
|
||||||
|
cachetimestamp = 0
|
||||||
|
|
||||||
def _get_keyring_cache():
|
def _get_keyring_cache():
|
||||||
global db
|
global db, cachetimestamp
|
||||||
if not db:
|
if db is None or (time.time() - cachetimestamp) > 86300:
|
||||||
import anydbm
|
import anydbm
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
import os.path
|
import os.path
|
||||||
filename = pkg_resources.resource_filename(__name__,
|
filename = pkg_resources.resource_filename(__name__,
|
||||||
'keyringcache')
|
'keyringcache')
|
||||||
|
logging.debug('reading cache data from %s', filename)
|
||||||
assert os.path.exists(filename) and os.path.isfile(filename)
|
assert os.path.exists(filename) and os.path.isfile(filename)
|
||||||
db = anydbm.open(filename, 'r')
|
db = anydbm.open(filename, 'r')
|
||||||
|
cachetimestamp = time.time()
|
||||||
return db
|
return db
|
||||||
|
|
||||||
def _get_cached(cachekey):
|
def _get_cached(cachekey):
|
||||||
cache = _get_keyring_cache()
|
cache = _get_keyring_cache()
|
||||||
|
logging.debug('cache lookup for %s', cachekey)
|
||||||
if cachekey in cache:
|
if cachekey in cache:
|
||||||
|
logging.debug('found entry %s', cache[cachekey])
|
||||||
return cache[cachekey]
|
return cache[cachekey]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,9 @@ import glob
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
|
import logging
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def _get_keyrings():
|
def _get_keyrings():
|
||||||
|
@ -40,6 +43,7 @@ def _get_keyrings():
|
||||||
my_config = ConfigParser.ConfigParser()
|
my_config = ConfigParser.ConfigParser()
|
||||||
my_config.readfp(pkg_resources.resource_stream(__name__, 'ddportfolio.ini'))
|
my_config.readfp(pkg_resources.resource_stream(__name__, 'ddportfolio.ini'))
|
||||||
keyringdir = os.path.expanduser(my_config.get('DEFAULT', 'keyring.dir'))
|
keyringdir = os.path.expanduser(my_config.get('DEFAULT', 'keyring.dir'))
|
||||||
|
logging.debug("keyring dir is %s", keyringdir)
|
||||||
keyrings = glob.glob(os.path.join(keyringdir, '*.gpg'))
|
keyrings = glob.glob(os.path.join(keyringdir, '*.gpg'))
|
||||||
keyrings.extend(glob.glob(os.path.join(keyringdir, '*.pgp')))
|
keyrings.extend(glob.glob(os.path.join(keyringdir, '*.pgp')))
|
||||||
keyrings.sort()
|
keyrings.sort()
|
||||||
|
@ -84,14 +88,16 @@ def process_keyrings():
|
||||||
"""Process the keyrings and store the extracted data in an anydbm
|
"""Process the keyrings and store the extracted data in an anydbm
|
||||||
file."""
|
file."""
|
||||||
for keyring in _get_keyrings():
|
for keyring in _get_keyrings():
|
||||||
contents = os.popen("gpg --no-default-keyring \
|
logging.debug("get data from %s", keyring)
|
||||||
--no-expensive-trust-checks \
|
proc = subprocess.Popen(["gpg", "--no-default-keyring",
|
||||||
--keyring %s --list-keys \
|
"--no-expensive-trust-checks",
|
||||||
--with-colons --fingerprint" % (keyring))
|
"--keyring", keyring, "--list-keys",
|
||||||
|
"--with-colons", "--fingerprint"],
|
||||||
|
stdout=subprocess.PIPE)
|
||||||
fpr = None
|
fpr = None
|
||||||
entry = None
|
entry = None
|
||||||
lastpub = None
|
lastpub = None
|
||||||
for line in contents.readlines():
|
for line in proc.stdout.readlines():
|
||||||
items = line.split(':')
|
items = line.split(':')
|
||||||
uid = None
|
uid = None
|
||||||
if items[0] == 'pub':
|
if items[0] == 'pub':
|
||||||
|
@ -119,7 +125,9 @@ def process_keyrings():
|
||||||
_add_to_result('name:fpr:%s' % fpr, uid)
|
_add_to_result('name:fpr:%s' % fpr, uid)
|
||||||
if email:
|
if email:
|
||||||
_add_to_result('name:email:%s' % email, uid)
|
_add_to_result('name:email:%s' % email, uid)
|
||||||
contents.close()
|
retcode = proc.wait()
|
||||||
|
if retcode != 0:
|
||||||
|
logging.error("subprocess ended with return code %d", retcode)
|
||||||
db = anydbm.open(pkg_resources.resource_filename(__name__,
|
db = anydbm.open(pkg_resources.resource_filename(__name__,
|
||||||
'keyringcache'), 'c')
|
'keyringcache'), 'c')
|
||||||
for key in resultdict:
|
for key in resultdict:
|
||||||
|
@ -128,4 +136,5 @@ def process_keyrings():
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
logging.basicConfig(stream=sys.stderr, level=logging.WARNING)
|
||||||
process_keyrings()
|
process_keyrings()
|
||||||
|
|
Loading…
Reference in a new issue