From 159be8fa02c62b9a9114c78edddc0913df21d636 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sat, 17 May 2014 21:31:47 +0200 Subject: [PATCH] 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. --- daklib/dbconn.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/daklib/dbconn.py b/daklib/dbconn.py index eee7a4ea..1bf82931 100644 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -1155,9 +1155,6 @@ def get_ldap_name(entry): ################################################################################ class Keyring(object): - gpg_invocation = "gpg --no-default-keyring --keyring %s" +\ - " --with-colons --fingerprint --fingerprint" - keys = {} fpr_lookup = {} @@ -1187,11 +1184,14 @@ class Keyring(object): if not self.keyring_id: 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 need_fingerprint = False - for line in k: + for line in p.stdout: field = line.split(":") if field[0] == "pub": key = field[4] @@ -1211,6 +1211,10 @@ class Keyring(object): self.fpr_lookup[field[9]] = key need_fingerprint = False + r = p.wait() + if r != 0: + raise subprocess.CalledProcessError(r, cmd) + def import_users_from_ldap(self, session): import ldap cnf = Config() -- 2.39.2