提交 159be8fa 编写于 作者: H Helmut Grohne

convert daklib.dbconn from os.popen to subprocess

It now explicitly closes the filedescriptors opened (by calling wait)
and checks the return code of gpg.
上级 ea5573c5
...@@ -1155,9 +1155,6 @@ def get_ldap_name(entry): ...@@ -1155,9 +1155,6 @@ def get_ldap_name(entry):
################################################################################ ################################################################################
class Keyring(object): class Keyring(object):
gpg_invocation = "gpg --no-default-keyring --keyring %s" +\
" --with-colons --fingerprint --fingerprint"
keys = {} keys = {}
fpr_lookup = {} fpr_lookup = {}
...@@ -1187,11 +1184,14 @@ class Keyring(object): ...@@ -1187,11 +1184,14 @@ class Keyring(object):
if not self.keyring_id: if not self.keyring_id:
raise Exception('Must be initialized with database information') raise Exception('Must be initialized with database information')
k = os.popen(self.gpg_invocation % keyring, "r") cmd = ["gpg", "--no-default-keyring", "--keyring", keyring,
"--with-colons", "--fingerprint", "--fingerprint"]
p = daklib.daksubprocess.Popen(cmd, stdout=subprocess.PIPE)
key = None key = None
need_fingerprint = False need_fingerprint = False
for line in k: for line in p.stdout:
field = line.split(":") field = line.split(":")
if field[0] == "pub": if field[0] == "pub":
key = field[4] key = field[4]
...@@ -1211,6 +1211,10 @@ class Keyring(object): ...@@ -1211,6 +1211,10 @@ class Keyring(object):
self.fpr_lookup[field[9]] = key self.fpr_lookup[field[9]] = key
need_fingerprint = False need_fingerprint = False
r = p.wait()
if r != 0:
raise subprocess.CalledProcessError(r, cmd)
def import_users_from_ldap(self, session): def import_users_from_ldap(self, session):
import ldap import ldap
cnf = Config() cnf = Config()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册