forked from jan/debianmemberportfolio
Port dddatabuilder and keyfinder to Python3
This commit is contained in:
parent
104e6701eb
commit
52066eb904
2 changed files with 12 additions and 9 deletions
|
@ -3,7 +3,7 @@
|
||||||
#
|
#
|
||||||
# Debian Member Portfolio Service data builder
|
# 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.
|
# This file is part of the Debian Member Portfolio Service.
|
||||||
#
|
#
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#
|
#
|
||||||
# Debian Member Portfolio Service key finder module
|
# 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.
|
# This file is part of the Debian Member Portfolio Service.
|
||||||
#
|
#
|
||||||
|
@ -36,14 +36,17 @@ cachetimestamp = 0
|
||||||
def _get_keyring_cache():
|
def _get_keyring_cache():
|
||||||
global db, cachetimestamp
|
global db, cachetimestamp
|
||||||
if db is None or (time.time() - cachetimestamp) > 86300:
|
if db is None or (time.time() - cachetimestamp) > 86300:
|
||||||
import anydbm
|
import dbm
|
||||||
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)
|
logging.debug('reading cache data from %s', filename)
|
||||||
assert os.path.exists(filename) and os.path.isfile(filename)
|
assert (
|
||||||
db = anydbm.open(filename, 'r')
|
os.path.exists(filename + '.db') and
|
||||||
|
os.path.isfile(filename + '.db')
|
||||||
|
)
|
||||||
|
db = dbm.open(filename, 'r')
|
||||||
cachetimestamp = time.time()
|
cachetimestamp = time.time()
|
||||||
return db
|
return db
|
||||||
|
|
||||||
|
@ -53,7 +56,7 @@ def _get_cached(cachekey):
|
||||||
logging.debug('cache lookup for %s', cachekey)
|
logging.debug('cache lookup for %s', cachekey)
|
||||||
if cachekey in cache:
|
if cachekey in cache:
|
||||||
logging.debug('found entry %s', cache[cachekey])
|
logging.debug('found entry %s', cache[cachekey])
|
||||||
return cache[cachekey]
|
return cache[cachekey].decode('utf8')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
@ -91,7 +94,7 @@ def getLoginByFingerprint(fpr):
|
||||||
def _dump_cache():
|
def _dump_cache():
|
||||||
cache = _get_keyring_cache()
|
cache = _get_keyring_cache()
|
||||||
fprs = []
|
fprs = []
|
||||||
for key in cache.keys():
|
for key in [key.decode('utf8') for key in list(cache.keys())]:
|
||||||
if key.startswith('email:fpr:'):
|
if key.startswith('email:fpr:'):
|
||||||
fpr = key.replace('email:fpr:', '')
|
fpr = key.replace('email:fpr:', '')
|
||||||
if not fpr in fprs:
|
if not fpr in fprs:
|
||||||
|
@ -102,8 +105,8 @@ def _dump_cache():
|
||||||
email = _get_cached('email:fpr:%s' % fpr)
|
email = _get_cached('email:fpr:%s' % fpr)
|
||||||
name = _get_cached('name:fpr:%s' % fpr)
|
name = _get_cached('name:fpr:%s' % fpr)
|
||||||
|
|
||||||
print fpr, login, ':'
|
print(fpr, login, ':')
|
||||||
print ' ', name, email
|
print(' ', name, email)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in a new issue