First pass at py3k compat

parent 2ba75493
#!/usr/bin/env python
from __future__ import print_function
import subprocess
import sys
import os
......@@ -13,12 +14,16 @@ os.environ['GNUPGHOME'] = os.path.relpath('.gnupg', os.path.dirname(mailmap))
key_lines = [
l.split(b' # ')[-1]
for l in open(mailmap)
for l in open(mailmap, 'rb')
if b' # ' in l]
valid_keys = []
for line in key_lines:
valid_keys.extend(map(str.strip, line.split(' ')))
valid_keys.extend(map(bytes.strip, line.split(b' ')))
for key in valid_keys:
print("Fetching key {}".format(key))
subprocess.call(['gpg2', '--keyserver', 'pool.sks-keyservers.net', '--recv-keys', key])
try:
subprocess.call(['gpg2', '--keyserver', 'pool.sks-keyservers.net', '--recv-keys', key])
except subprocess.CalledProcessError:
print("Failed!")
print("Success!")
......@@ -12,11 +12,11 @@ mailmap = sys.argv[2]
key_lines = [
l.split(b' # ')[-1]
for l in open(mailmap)
for l in open(mailmap, 'rb')
if b' # ' in l]
valid_keys = []
for line in key_lines:
valid_keys.extend(map(str.strip, line.split(' ')))
valid_keys.extend(map(bytes.strip, line.split(b' ')))
commits = pexpect.run('git rev-list --full-history ' + which)
......@@ -26,37 +26,37 @@ commits = pexpect.run('git rev-list --full-history ' + which)
metapath = os.path.join(os.path.dirname(mailmap), '.revoked-keys')
revoked = {}
for line in open(metapath):
if line.startswith('#') or not l:
for line in open(metapath, 'rb'):
if line.startswith(b'#') or not l:
continue
parts = line.split(' ')
parts = line.split(b' ')
revoked[parts[0]] = parts[1:]
toplevel = pexpect.run('git rev-parse --show-toplevel').strip()
try:
ignored_commits = [l.strip()
for l in open(os.path.join(toplevel, '.signing-exceptions'))
for l in open(os.path.join(toplevel, '.signing-exceptions'), 'rb')
if l and not l.startswith('#')]
except Exception as e:
ignored_commits = [] # fail safe, usual error is no .signing-exceptions
try:
ignored_commits = [l.strip() for l in open(os.path.join(pexpect.run('git rev-parse --show-toplevel').strip(),
'.signing-exceptions')) if l and not l.startswith('#')]
'.signing-exceptions'), 'rb') if l and not l.startswith(b'#')]
except Exception as e:
ignored_commits = [] # fail safe, usual error is no .signing-exceptions
for commit in commits.split():
if commit not in ignored_commits:
gpgdump = pexpect.run('git verify-commit --raw ' + commit)
sigs = [l for l in gpgdump.split('\r\n') if 'VALIDSIG' in l]
sigs = [l for l in gpgdump.split(b'\r\n') if b'VALIDSIG' in l]
if not sigs:
print("ERROR: no valid signature for commit {}".format(commit))
sys.exit(1)
elif len(sigs) > 1:
print("More than one valid signature?")
keyid = sigs[0].split(' ')[-1].strip()
keyid = sigs[0].split(b' ')[-1].strip()
if keyid not in valid_keys:
print("ERROR: commit {} signed with unrecognized key {}".format(commit, keyid))
sys.exit(2)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment