diff options
| author | 2018-04-04 04:50:04 +0200 | |
|---|---|---|
| committer | 2018-04-04 04:50:04 +0200 | |
| commit | 1cd7d0f0248e2fe317b2e3da9f597059cf30b4d9 (patch) | |
| tree | ec37a444ed314f7bfd4395cd42ee54d7b70debf0 /minidinstall | |
| parent | 11bda2c49979375ab7cdea5deac04f4bcb2a5dae (diff) | |
Switch to using the subprocess module.
Diffstat (limited to 'minidinstall')
| -rw-r--r-- | minidinstall/GPGSigVerifier.py | 43 |
1 files changed, 15 insertions, 28 deletions
diff --git a/minidinstall/GPGSigVerifier.py b/minidinstall/GPGSigVerifier.py index 0d47379..8c17bfe 100644 --- a/minidinstall/GPGSigVerifier.py +++ b/minidinstall/GPGSigVerifier.py @@ -18,8 +18,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -import os -from . import misc +import os, subprocess class GPGSigVerifierException(Exception): def __init__(self, value): @@ -47,31 +46,19 @@ class GPGSigVerifier: self._gpgv = gpgv def verify(self, filename, sigfilename=None): - (stdin, stdout) = os.pipe() - pid = os.fork() - if pid == 0: - os.close(stdin) - misc.dup2(stdout, 1) - misc.dup2(stdout, 2) - args = [self._gpgv] - for keyring in self._keyrings: - args.extend(['--keyring', keyring]) - if sigfilename: - args.append(sigfilename) - args.append(filename) - os.execv(self._gpgv, args) - os.exit(1) - os.close(stdout) - output = os.fdopen(stdin).readlines() - (pid, status) = os.waitpid(pid, 0) - if status or (not os.WIFEXITED(status) and os.WEXITSTATUS(status) != 0): - if os.WIFEXITED(status): - msg = "gpgv exited with error code %d" % os.WEXITSTATUS(status) - elif os.WIFSTOPPED(status): - msg = "gpgv stopped unexpectedly with signal %d" % os.WSTOPSIG(status) - elif os.WIFSIGNALED(status): - msg = "gpgv died with signal %d" % os.WTERMSIG(status) - raise GPGSigVerificationFailure(msg, output) - return output + cmdline = [self._gpgv] + for keyring in self._keyrings: + cmdline.extend(['--keyring', keyring]) + if sigfilename: + cmdline.append(sigfilename) + cmdline.append(filename) + try: + return subprocess.check_output(cmdline).decode('utf-8') + except subprocess.CalledProcessError as e: + if e.returncode > 0: + msg = "gpgv exited with error code %d" % e.returncode + else: + msg = "gpgv died with signal %d" % -e.returncode + raise GPGSigVerificationFailure(msg, e.output) # vim:ts=4:sw=4:et: |
