From c3b5dbc316b79f07b2a4aa5c5e1d14802faa8d69 Mon Sep 17 00:00:00 2001 From: Bezleputh Date: Tue, 25 Nov 2014 13:56:07 +0100 Subject: [PATCH] [windows] fix probleme using NamedTemporaryFile on windows --- weboob/core/repositories.py | 39 +++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/weboob/core/repositories.py b/weboob/core/repositories.py index 0f9cc6b4..49e5f424 100644 --- a/weboob/core/repositories.py +++ b/weboob/core/repositories.py @@ -777,21 +777,30 @@ class Keyring(object): """ gpgv = self.find_gpgv() from tempfile import NamedTemporaryFile - with NamedTemporaryFile(suffix='.sig') as sigfile: - sigfile.write(sigdata) - sigfile.flush() # very important - assert isinstance(data, basestring) - # Yes, all of it is necessary - proc = subprocess.Popen([gpgv, - '--status-fd', '1', - '--keyring', os.path.realpath(self.path), - os.path.realpath(sigfile.name), - '-'], - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - out, err = proc.communicate(data) - if proc.returncode or 'GOODSIG' not in out or 'VALIDSIG' not in out: + with NamedTemporaryFile(suffix='.sig', delete=False) as sigfile: + temp_filename = sigfile.name + return_code = None + out = '' + err = '' + try: + sigfile.write(sigdata) + sigfile.flush() # very important + assert isinstance(data, basestring) + # Yes, all of it is necessary + proc = subprocess.Popen([gpgv, + '--status-fd', '1', + '--keyring', os.path.realpath(self.path), + os.path.realpath(sigfile.name), + '-'], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + out, err = proc.communicate(data) + return_code = proc.returncode + finally: + os.unlink(temp_filename) + + if return_code or 'GOODSIG' not in out or 'VALIDSIG' not in out: print(out, err, file=sys.stderr) return False return True