Port dddatabuilder and keyfinder to Python3

This commit is contained in:
Jan Dittberner 2015-11-11 00:48:01 +01:00
parent 104e6701eb
commit 52066eb904
2 changed files with 12 additions and 9 deletions

View file

@ -3,7 +3,7 @@
#
# Debian Member Portfolio Service data builder
#
# Copyright © 2009-2014 Jan Dittberner <jan@dittberner.info>
# Copyright © 2009-2015 Jan Dittberner <jan@dittberner.info>
#
# This file is part of the Debian Member Portfolio Service.
#

View file

@ -3,7 +3,7 @@
#
# Debian Member Portfolio Service key finder module
#
# Copyright © 2009-2014 Jan Dittberner <jan@dittberner.info>
# Copyright © 2009-2015 Jan Dittberner <jan@dittberner.info>
#
# This file is part of the Debian Member Portfolio Service.
#
@ -36,14 +36,17 @@ cachetimestamp = 0
def _get_keyring_cache():
global db, cachetimestamp
if db is None or (time.time() - cachetimestamp) > 86300:
import anydbm
import dbm
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')
assert (
os.path.exists(filename + '.db') and
os.path.isfile(filename + '.db')
)
db = dbm.open(filename, 'r')
cachetimestamp = time.time()
return db
@ -53,7 +56,7 @@ def _get_cached(cachekey):
logging.debug('cache lookup for %s', cachekey)
if cachekey in cache:
logging.debug('found entry %s', cache[cachekey])
return cache[cachekey]
return cache[cachekey].decode('utf8')
return None
@ -91,7 +94,7 @@ def getLoginByFingerprint(fpr):
def _dump_cache():
cache = _get_keyring_cache()
fprs = []
for key in cache.keys():
for key in [key.decode('utf8') for key in list(cache.keys())]:
if key.startswith('email:fpr:'):
fpr = key.replace('email:fpr:', '')
if not fpr in fprs:
@ -102,8 +105,8 @@ def _dump_cache():
email = _get_cached('email:fpr:%s' % fpr)
name = _get_cached('name:fpr:%s' % fpr)
print fpr, login, ':'
print ' ', name, email
print(fpr, login, ':')
print(' ', name, email)
if __name__ == '__main__':