summaryrefslogtreecommitdiff
path: root/errno
blob: ba951053bbe9cbe14009bc092ba09bd395ea5324 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/python

import errno
import os
import sys

names = [name for name in dir(errno) if name.startswith('E')]
codes = dict((name, getattr(errno, name)) for name in names)
texts = dict((name, os.strerror(codes[name])) for name in names)

def report(name):
    print name, codes[name], texts[name]

for arg in sys.argv[1:]:
    if arg in names:
        report(arg)
    else:
        for name, code in codes.iteritems():
            if arg == str(code):
                report(name)
                break
        else:
            found = False
            for name, text in texts.iteritems():
                if arg.lower() in text.lower():
                    report(name)
                    found = True
            if not found:
                print 'Unknown:', arg