diff options
author | Lars Wirzenius <liw@liw.fi> | 2009-10-29 22:36:04 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2009-10-29 22:36:04 +0200 |
commit | 90ddb0b8eb915bef9acaf94356f7a48deefdde32 (patch) | |
tree | 11261312def9ccea771da3cf5918dbb813603690 | |
parent | c592d681fd29980244d96b5bdd061216d0827263 (diff) | |
download | extrautils-90ddb0b8eb915bef9acaf94356f7a48deefdde32.tar.gz |
errno can now search error texts, too
-rwxr-xr-x | errno | 32 |
1 files changed, 21 insertions, 11 deletions
@@ -4,17 +4,27 @@ import errno import os import sys -toname = dict((str(getattr(errno, x)), x) - for x in dir(errno) - if x.startswith("E")) -tocode = dict((x, getattr(errno, x)) - for x in dir(errno) - if x.startswith("E")) +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 tocode: - print arg, tocode[arg], os.strerror(tocode[arg]) - elif arg in toname: - print toname[arg], arg, os.strerror(int(arg)) + if arg in names: + report(arg) else: - print "Unknown:", arg + 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 + |