Skip to content

Instantly share code, notes, and snippets.

@F30
Created September 27, 2017 10:02
Show Gist options
  • Save F30/388ff62601eaa53e9f2ce247443e3ad4 to your computer and use it in GitHub Desktop.
Save F30/388ff62601eaa53e9f2ce247443e3ad4 to your computer and use it in GitHub Desktop.
List GPG Ownertrust
#!/usr/bin/env python3
import sys
import os
import gnupg
TRUST_LEVEL_MAP = {
'q': '???',
'n': 'Not',
'm': 'Marginal',
'f': 'Full',
'u': 'Ultimate'
}
def main():
gpg = gnupg.GPG()
gpg.encoding = 'utf-8'
keys = gpg.list_keys()
trust_keys = filter(lambda k: k['ownertrust'] != '-', keys)
for key in trust_keys:
trust_level = TRUST_LEVEL_MAP[key['ownertrust']]
print('{} {:<59} {}'.format(key['keyid'], key['uids'][0], trust_level))
return os.EX_OK
if __name__ == '__main__':
sys.exit(main())
@x10an14
Copy link

x10an14 commented Jun 24, 2021

Minor suggestions update for more in-line with a different style of python3 syntax =)

#!/usr/bin/env python3

import os
import sys

import gnupg


TRUST_LEVEL_MAP = {
    'q': '???',
    'n': 'Not',
    'm': 'Marginal',
    'f': 'Full',
    'u': 'Ultimate'
}


def main():
    gpg = gnupg.GPG()
    gpg.encoding = 'utf-8'

    trust_keys = [
        key
        for key
        in gpg.list_keys()
        if key['ownertrust'] != '-'
    ]

    for key in trust_keys:
        trust_level = TRUST_LEVEL_MAP[key['ownertrust']]
        print(f"{key['keyid']}:{trust_level}:{key['uids'][0]}")

    return os.EX_OK


if __name__ == '__main__':
    sys.exit(main())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment