summaryrefslogtreecommitdiff
path: root/errno
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2009-10-29 22:36:04 +0200
committerLars Wirzenius <liw@liw.fi>2009-10-29 22:36:04 +0200
commit90ddb0b8eb915bef9acaf94356f7a48deefdde32 (patch)
tree11261312def9ccea771da3cf5918dbb813603690 /errno
parentc592d681fd29980244d96b5bdd061216d0827263 (diff)
downloadextrautils-90ddb0b8eb915bef9acaf94356f7a48deefdde32.tar.gz
errno can now search error texts, too
Diffstat (limited to 'errno')
-rwxr-xr-xerrno32
1 files changed, 21 insertions, 11 deletions
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
+