X-Git-Url: https://git.tld-linux.org/?a=blobdiff_plain;f=TLD_Builder%2Fgpg.py;h=b820dcdf3d4821ee7d3acd7edf47e4c26994e2f9;hb=99c8ec16ca741caf94419fa7976525744ce9aed1;hp=055c39083d286eb95263b4c7c271bcb5b8753809;hpb=92949e17161a53bfb4a60099e22b58ad63abce4c;p=tld-builder.git diff --git a/TLD_Builder/gpg.py b/TLD_Builder/gpg.py index 055c390..b820dcd 100644 --- a/TLD_Builder/gpg.py +++ b/TLD_Builder/gpg.py @@ -20,14 +20,14 @@ def get_keys(buf): if not os.path.isfile('/usr/bin/gpg'): log.error("missing gnupg binary: /usr/bin/gpg") - raise OSError, 'Missing gnupg binary' + raise OSError('Missing gnupg binary') d_stdout = None d_stderr = None cmd = ['/usr/bin/gpg', '--batch', '--no-tty', '--decrypt'] gpg_run = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) try: - d_stdout, d_stderr = gpg_run.communicate(buf.encode('utf-8')) + d_stdout, d_stderr = gpg_run.communicate(buf.decode().encode('utf-8')) except OSError as e: log.error("gnupg run, does gpg binary exist? : %s" % e) raise @@ -35,7 +35,7 @@ def get_keys(buf): rx = re.compile("^gpg:.*using\s[DR]SA\skey\s(?:ID\s)?(\w+)") keys = [] - for l in d_stderr.split('\n'): + for l in d_stderr.decode().split('\n'): m = rx.match(l) if m: keys.append(m.group(1)) @@ -52,21 +52,21 @@ def verify_sig(buf): if not os.path.isfile('/usr/bin/gpg'): log.error("missing gnupg binary: /usr/bin/gpg") - raise OSError, 'Missing gnupg binary' + raise OSError('Missing gnupg binary') d_stdout = None d_stderr = None cmd = ['/usr/bin/gpg', '--batch', '--no-tty', '--decrypt'] gpg_run = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) try: - d_stdout, d_stderr = gpg_run.communicate(buf.encode('utf-8')) + d_stdout, d_stderr = gpg_run.communicate(buf.decode().encode('utf-8')) except OSError as e: log.error("gnupg run failed, does gpg binary exist? : %s" % e) raise rx = re.compile("^gpg: (Good signature from| aka) .*<([^>]+)>") emails = [] - for l in d_stderr.split('\n'): + for l in d_stderr.decode().split('\n'): m = rx.match(l) if m: emails.append(m.group(2)) @@ -77,7 +77,7 @@ def verify_sig(buf): def sign(buf): if not os.path.isfile('/usr/bin/gpg'): log.error("missing gnupg binary: /usr/bin/gpg") - raise OSError, 'Missing gnupg binary' + raise OSError('Missing gnupg binary') d_stdout = None d_stderr = None @@ -85,12 +85,12 @@ def sign(buf): # TODO: check for gpg return code! gpg_run = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) try: - d_stdout, d_stderr = gpg_run.communicate(buf.encode('utf-8')) + d_stdout, d_stderr = gpg_run.communicate(buf.decode().encode('utf-8')) except OSError as e: log.error("gnupg signing failed, does gpg binary exist? : %s" % e) raise if len(d_stderr): - log.error("gpg: %s" % d_stderr) + log.error("gpg: %s" % d_stderr.decode()) return d_stdout