From 90ddb0b8eb915bef9acaf94356f7a48deefdde32 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 29 Oct 2009 22:36:04 +0200 Subject: errno can now search error texts, too --- errno | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'errno') diff --git a/errno b/errno index d801faa..ba95105 100755 --- a/errno +++ b/errno @@ -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 + -- cgit v1.2.1