summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Buesch <m@bues.ch>2012-04-14 14:34:34 +0200
committerMichael Buesch <m@bues.ch>2012-04-14 14:34:34 +0200
commit1e00ee0dacff180d31e2fe60c46de61e32b45226 (patch)
tree1d3a7f0befaf1de55dabfa1e76ca34b204522edf
parent17cca19572149b05895e893d2b8025ed34c7c6e5 (diff)
downloadtoprammer-1e00ee0dacff180d31e2fe60c46de61e32b45226.tar.xz
toprammer-1e00ee0dacff180d31e2fe60c46de61e32b45226.zip
Add str2bool helper
Signed-off-by: Michael Buesch <m@bues.ch>
-rw-r--r--libtoprammer/util.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/libtoprammer/util.py b/libtoprammer/util.py
index a546999..b9bcd14 100644
--- a/libtoprammer/util.py
+++ b/libtoprammer/util.py
@@ -67,6 +67,18 @@ def bytes2ascii(bindata):
return ""
return "".join(map(byte2ascii, bindata))
+def str2bool(string):
+ string = str(string).lower().strip()
+ if string in ("false", "off", "no"):
+ return False
+ if string in ("true", "on", "yes"):
+ return True
+ try:
+ return bool(int(string, 10))
+ except (ValueError), e:
+ pass
+ return None
+
def genRandomBlob(size):
blob = map(lambda x: int2byte(random.randint(0, 0xFF)),
range(0, size))
bues.ch cgit interface