Title: Visualising gpg web of trust with python
Date: 2013-10-25 18:00

The last time I explained to someone the concept of gpg and web of trust,
this person was a little bit disappointed: I was unable to
show her a visual map of my web. Yes, I know, someone did such a tool in Perl.
But:

    1. It's in Perl
    2. It does not work anymore

I hacked the following script in Python to create such a map. It *works for me*. Feel free to make it work for you, and to complain about the fact that you had to fix it.

```python
#!/usr/bin/python

'''
    Simple script to visualise your GPG Web of Trust

    Usage:
        gpg --list-sigs | ./sigps.py > out.dot

            circo -Tpdf test.dot > test.pdf
        or
            dot -Tpdf test.dot > test.pdf

    GPLv2 - jvoisin - dustri.org

'''

import fileinput

lines = [i for i in fileinput.input() if not i.startswith('sub')]
lines.reverse()

public = dict()

while lines:
    signers = set()
    breakers = set()
    line = lines.pop()
    while not line.startswith('uid'):
        line = lines.pop()
    uid = line.split()[-1]
    while True:
        line = lines.pop()
        if line.startswith('uid') and 'jpeg image' not in line:
            if uid not in line:
                signers.add(line.split()[-1])
        elif line.startswith('sig'):
            if 'User ID not found' not in line:
                if uid not in line:
                    signers.add(line.split()[-1])
        elif line.startswith('rev'):
            breakers.add(line.split()[-1])
        else:
            break
    public[uid] = [signers, breakers]

print('digraph graphname {')
for key, items in public.iter():
    for signers in items[0]:
        print('"' + signers + '"->"' + key + '"[color=blue];')
    for breakers in items[1]:
        print('"' + breakers + '"->"' + key + '"[color=red];')
print('}')
```

