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/>.
|
||||
#
|
||||
[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,
|
||||
miscellaneous,ssh,ubuntu
|
||||
|
||||
|
|
|
@ -24,24 +24,31 @@
|
|||
This module provides tools for finding PGP key information from a
|
||||
given keyring.
|
||||
"""
|
||||
import logging
|
||||
import time
|
||||
|
||||
db = None
|
||||
cachetimestamp = 0
|
||||
|
||||
def _get_keyring_cache():
|
||||
global db
|
||||
if not db:
|
||||
global db, cachetimestamp
|
||||
if db is None or (time.time() - cachetimestamp) > 86300:
|
||||
import anydbm
|
||||
import pkg_resources
|
||||
import os.path
|
||||
filename = pkg_resources.resource_filename(__name__,
|
||||
'keyringcache')
|
||||
logging.debug('reading cache data from %s', filename)
|
||||
assert os.path.exists(filename) and os.path.isfile(filename)
|
||||
db = anydbm.open(filename, 'r')
|
||||
cachetimestamp = time.time()
|
||||
return db
|
||||
|
||||
def _get_cached(cachekey):
|
||||
cache = _get_keyring_cache()
|
||||
logging.debug('cache lookup for %s', cachekey)
|
||||
if cachekey in cache:
|
||||
logging.debug('found entry %s', cache[cachekey])
|
||||
return cache[cachekey]
|
||||
return None
|
||||
|
||||
|
|
|
@ -32,6 +32,9 @@ import glob
|
|||
import ConfigParser
|
||||
import os
|
||||
import os.path
|
||||
import logging
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def _get_keyrings():
|
||||
|
@ -40,6 +43,7 @@ def _get_keyrings():
|
|||
my_config = ConfigParser.ConfigParser()
|
||||
my_config.readfp(pkg_resources.resource_stream(__name__, 'ddportfolio.ini'))
|
||||
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.extend(glob.glob(os.path.join(keyringdir, '*.pgp')))
|
||||
keyrings.sort()
|
||||
|
@ -84,14 +88,16 @@ def process_keyrings():
|
|||
"""Process the keyrings and store the extracted data in an anydbm
|
||||
file."""
|
||||
for keyring in _get_keyrings():
|
||||
contents = os.popen("gpg --no-default-keyring \
|
||||
--no-expensive-trust-checks \
|
||||
--keyring %s --list-keys \
|
||||
--with-colons --fingerprint" % (keyring))
|
||||
logging.debug("get data from %s", keyring)
|
||||
proc = subprocess.Popen(["gpg", "--no-default-keyring",
|
||||
"--no-expensive-trust-checks",
|
||||
"--keyring", keyring, "--list-keys",
|
||||
"--with-colons", "--fingerprint"],
|
||||
stdout=subprocess.PIPE)
|
||||
fpr = None
|
||||
entry = None
|
||||
lastpub = None
|
||||
for line in contents.readlines():
|
||||
for line in proc.stdout.readlines():
|
||||
items = line.split(':')
|
||||
uid = None
|
||||
if items[0] == 'pub':
|
||||
|
@ -119,7 +125,9 @@ def process_keyrings():
|
|||
_add_to_result('name:fpr:%s' % fpr, uid)
|
||||
if email:
|
||||
_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__,
|
||||
'keyringcache'), 'c')
|
||||
for key in resultdict:
|
||||
|
@ -128,4 +136,5 @@ def process_keyrings():
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logging.basicConfig(stream=sys.stderr, level=logging.WARNING)
|
||||
process_keyrings()
|
||||
|
|
Loading…
Reference in a new issue