port keyringanalyzer to Python3

- ran through 2to3
- switch to new ConfigParser name
- fix UTF-8 handling of gpg output
- don't track tags and keyringcache.db in git
This commit is contained in:
Jan Dittberner 2015-09-25 12:08:48 +02:00
parent f63939cb03
commit cf04f6f0cb
2 changed files with 11 additions and 9 deletions

2
.gitignore vendored
View file

@ -6,3 +6,5 @@ data/
.ropeproject/ .ropeproject/
*.mo *.mo
*.pot *.pot
tags
debianmemberportfolio/model/keyringcache.db

View file

@ -3,7 +3,7 @@
# #
# Debian Member Portfolio Service application key ring analyzer tool # Debian Member Portfolio Service application key ring analyzer tool
# #
# 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.
# #
@ -26,10 +26,10 @@ retrieved data in a file database. The tool was inspired by Debian
qa's carnivore. qa's carnivore.
""" """
import anydbm import dbm
import pkg_resources import pkg_resources
import glob import glob
import ConfigParser import configparser
import os import os
import os.path import os.path
import logging import logging
@ -38,7 +38,7 @@ import sys
import email.utils import email.utils
CONFIG = ConfigParser.SafeConfigParser() CONFIG = configparser.ConfigParser()
def _get_keyrings(): def _get_keyrings():
@ -160,11 +160,11 @@ def process_keyrings():
stdout=subprocess.PIPE) stdout=subprocess.PIPE)
fpr = None fpr = None
for line in proc.stdout.readlines(): for line in proc.stdout.readlines():
fpr = process_gpg_list_keys_line(line, fpr) fpr = process_gpg_list_keys_line(line.decode('utf8'), fpr)
retcode = proc.wait() retcode = proc.wait()
if retcode != 0: if retcode != 0:
logging.error("subprocess ended with return code %d", retcode) logging.error("subprocess ended with return code %d", retcode)
db = anydbm.open(pkg_resources.resource_filename(__name__, db = dbm.open(pkg_resources.resource_filename(__name__,
'keyringcache'), 'c') 'keyringcache'), 'c')
for key in resultdict: for key in resultdict:
db[key] = ":".join(resultdict[key]) db[key] = ":".join(resultdict[key])
@ -173,9 +173,9 @@ def process_keyrings():
if __name__ == '__main__': if __name__ == '__main__':
logging.basicConfig(stream=sys.stderr, level=logging.WARNING) logging.basicConfig(stream=sys.stderr, level=logging.WARNING)
CONFIG.readfp(pkg_resources.resource_stream( CONFIG.read_string(pkg_resources.resource_string(
__name__, 'portfolio.ini')) __name__, 'portfolio.ini').decode('utf8'))
gpghome = os.path.expanduser(CONFIG.get('DEFAULT', 'gnupghome')) gpghome = os.path.expanduser(CONFIG.get('DEFAULT', 'gnupghome'))
if not os.path.isdir(gpghome): if not os.path.isdir(gpghome):
os.makedirs(gpghome, 0700) os.makedirs(gpghome, 0o700)
process_keyrings() process_keyrings()