[node-patches] Change in ovirt-node[master]: utils: Add parse_bool
fabiand at fedoraproject.org
fabiand at fedoraproject.org
Tue Dec 11 20:09:38 UTC 2012
Fabian Deutsch has uploaded a new change for review.
Change subject: utils: Add parse_bool
......................................................................
utils: Add parse_bool
Change-Id: I5221ba890c0360fd61c0f71f45e41b249b9c9198
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/ovirt/node/utils/__init__.py
1 file changed, 26 insertions(+), 2 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/21/9921/1
diff --git a/scripts/tui/src/ovirt/node/utils/__init__.py b/scripts/tui/src/ovirt/node/utils/__init__.py
index 1f486ba..f8c1728 100644
--- a/scripts/tui/src/ovirt/node/utils/__init__.py
+++ b/scripts/tui/src/ovirt/node/utils/__init__.py
@@ -58,7 +58,6 @@
return self._aug.match(p)
-
def checksum(filename, algo="md5"):
"""Calculcate the checksum for a file.
"""
@@ -70,7 +69,6 @@
m.update(data)
data = f.read(4096)
return m.hexdigest()
-
def is_bind_mount(filename, fsprefix="ext"):
@@ -88,3 +86,29 @@
if pattern in mount:
bind_mount_found = True
return bind_mount_found
+
+
+def parse_bool(txt):
+ """Parse common "bool" values (yes, no, true, false, 1)
+
+ >>> parse_bool(True)
+ True
+
+ >>> txts = ["yes", "YES!", "1", 1]
+ >>> all((parse_bool(txt) for txt in txts))
+ True
+
+ >>> txts = ["no", "NO!", "0", 0, False, None, "foo"]
+ >>> all((not parse_bool(txt) for txt in txts))
+ True
+
+ Args:
+ txt: Text to be parsed
+ Returns:
+ True if it looks like a bool representing True, False otherwise
+ """
+ if txt != None and type(txt) in [str, unicode, int, bool]:
+ utxt = unicode(txt)
+ if len(utxt) > 0 and utxt[0] in ["y", "t", "Y", "T", "1"]:
+ return True
+ return False
--
To view, visit http://gerrit.ovirt.org/9921
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5221ba890c0360fd61c0f71f45e41b249b9c9198
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>
More information about the node-patches
mailing list