Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env python3
import os
import subprocess
import re
def main():
pubring = os.path.join(os.getenv("HOME", "~"), ".gnupg", "pubring.gpg")
output = subprocess.check_output(["gpg", "--list-packets", pubring])
output = output.decode("utf8")
items = output.split("\n#")
current_keyid = "??"
counts = {}
for item in items:
if ":public key packet:" in item:
m ='keyid: ([0-9a-fA-F]+)', item)
current_keyid =
if ":signature packet:" in item:
counts[current_keyid] = counts.get(current_keyid, 0) + 1
for key in counts.keys():
print(key, counts[key])
if __name__ == "__main__":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment