From 17e11493efdfd893b53f38bd945c541b2c20b952 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sun, 29 Mar 2009 12:49:15 +0100 Subject: [PATCH] Removed used of deprecated os.open2 Better unit-test for gpg.load_keys. --- tests/testgpg.py | 12 ++++++++++-- zeroinstall/injector/gpg.py | 12 ++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/tests/testgpg.py b/tests/testgpg.py index 58cdbd3..24aedfe 100755 --- a/tests/testgpg.py +++ b/tests/testgpg.py @@ -96,6 +96,8 @@ Uk7hxHFeQPo= from data import thomas_key +THOMAS_FINGERPRINT = '92429807C9853C0744A68B9AAE07828059A53CC1' + class TestGPG(BaseTest): def setUp(self): BaseTest.setUp(self) @@ -104,8 +106,7 @@ class TestGPG(BaseTest): stream.write(thomas_key) stream.seek(0) gpg.import_key(stream) - trust.trust_db.trust_key( - '92429807C9853C0744A68B9AAE07828059A53CC1') + trust.trust_db.trust_key(THOMAS_FINGERPRINT) def testImportBad(self): stream = tempfile.TemporaryFile() @@ -197,7 +198,14 @@ class TestGPG(BaseTest): pass # OK def testLoadKeys(self): + self.assertEquals({}, gpg.load_keys([])) + keys = gpg.load_keys([THOMAS_FINGERPRINT]) + self.assertEquals(1, len(keys)) + key = keys[THOMAS_FINGERPRINT] + self.assertEquals(THOMAS_FINGERPRINT, key.fingerprint) + self.assertEquals('Thomas Leonard ', + key.name) suite = unittest.makeSuite(TestGPG) if __name__ == '__main__': diff --git a/zeroinstall/injector/gpg.py b/zeroinstall/injector/gpg.py index 772959e..e472160 100644 --- a/zeroinstall/injector/gpg.py +++ b/zeroinstall/injector/gpg.py @@ -13,7 +13,7 @@ import subprocess import base64, re import os import tempfile -from logging import info +from logging import info, warn from zeroinstall.support import find_in_path, basedir from zeroinstall.injector.trust import trust_db @@ -133,11 +133,10 @@ def load_keys(fingerprints): current_fpr = None current_uid = None - cin, cout = os.popen2(_gnupg_options + ['--fixed-list-mode', '--with-colons', '--list-keys', - '--with-fingerprint', '--with-fingerprint'] + fingerprints) - cin.close() + child = subprocess.Popen(_gnupg_options + ['--fixed-list-mode', '--with-colons', '--list-keys', + '--with-fingerprint', '--with-fingerprint'] + fingerprints, stdout = subprocess.PIPE) try: - for line in cout: + for line in child.stdout: if line.startswith('pub:'): current_fpr = None current_uid = None @@ -157,7 +156,8 @@ def load_keys(fingerprints): if current_fpr in keys: keys[current_fpr].name = current_uid finally: - cout.close() + if child.wait(): + warn("gpg --list-keys failed with exit code %d" % child.returncode) return keys -- 2.11.4.GIT