Created
February 8, 2017 16:34
-
-
Save spacecowboy/d216c14a2e494bae0228cb32cc53b8c4 to your computer and use it in GitHub Desktop.
Script which outputs a key list with 'X'-es on the keys you've verified.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
''' | |
Usage: {} <ksp-fosdem.txt> <result.txt> | |
Marks which keys you have verified from a keysigning party. | |
Tested on FOSDEM keysigning party 2017. | |
''' | |
import sys | |
import re | |
def ask(num): | |
userinput = None | |
while userinput is None: | |
try: | |
userinput = input("{:03d}? (y/N/<num>): ".format(num)) | |
except EOFError: | |
print("\nEnter y for yes, anything else for no. A number is a shortcut to enter no and jump to that number.") | |
return userinput | |
def main(infile, outfile): | |
with open(infile, 'r') as IN: | |
lines = IN.readlines() | |
header = True | |
xline = re.compile(r'(\d+).+Fingerprint OK.+ID OK') | |
okline = "{:03d} [x] Fingerprint OK [x] ID OK" | |
next_num = 0 | |
with open(outfile, 'w') as OUT: | |
for line in lines: | |
if header: | |
print(line, end='', file=OUT) | |
header = "BEGIN KEY LIST" not in line | |
continue | |
m = xline.match(line) | |
if m: | |
num = int(m.group(1)) | |
if num >= next_num: | |
userinput = ask(num) | |
if userinput.lower() == "y": | |
print(okline.format(num), file=OUT) | |
else: | |
print(line, end='', file=OUT) | |
try: | |
usernum = int(userinput) | |
next_num = usernum | |
except ValueError: | |
pass | |
else: | |
print(line, end='', file=OUT) | |
else: | |
print(line, end='', file=OUT) | |
if __name__ == "__main__": | |
if len(sys.argv) != 3: | |
exit(__doc__.format(sys.argv[0])) | |
main(sys.argv[1], sys.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment