commit 1ccb815a7ebe0d8376b72c128f1dc3d79cdff645
Author: Jiri Pirko <jiri(a)resnulli.us>
Date: Fri Sep 21 12:44:52 2012 -0400
move bool_it and int_it into Common.Utils
Signed-off-by: Jiri Pirko <jiri(a)resnulli.us>
Common/Utils.py | 15 +++++++++++++++
NetTest/NetTestParse.py | 21 ++-------------------
2 files changed, 17 insertions(+), 19 deletions(-)
---
diff --git a/Common/Utils.py b/Common/Utils.py
index 5f3f251..bae3043 100644
--- a/Common/Utils.py
+++ b/Common/Utils.py
@@ -70,3 +70,18 @@ def kmod_in_use(modulename, tries = 1):
if (ret and tries):
return kmod_in_use(modulename, tries)
return ret
+
+def int_it(val):
+ try:
+ num = int(val)
+ except ValueError:
+ num = 0
+ return num
+
+def bool_it(val):
+ if isinstance(val, str):
+ if re.match("^\s*(?i)(true)", val):
+ return True
+ elif re.match("^\s*(?i)(false)", val):
+ return False
+ return True if int_it(val) else False
diff --git a/NetTest/NetTestParse.py b/NetTest/NetTestParse.py
index 4f54624..76068dd 100644
--- a/NetTest/NetTestParse.py
+++ b/NetTest/NetTestParse.py
@@ -17,6 +17,7 @@ from Common.XmlProcessing import RecipeParser
from Common.XmlProcessing import XmlDomTreeInit
from Common.XmlProcessing import XmlProcessingError
from Common.NetUtils import normalize_hwaddr
+from Common.Utils import bool_it
class NetTestParse(RecipeParser):
def __init__(self, recipe_filepath):
@@ -428,7 +429,7 @@ class CommandParse(RecipeParser):
if self._has_attribute(node, "persistent"):
command["persistent"] = self._get_attribute(node,
"persistent",
- self._bool_it)
+ bool_it)
else:
command["persistent"] = False
@@ -471,21 +472,3 @@ class CommandParse(RecipeParser):
else:
msg = "Unknown option type \"%s\"" % opt_type
raise XmlProcessingError(msg, node)
-
-
- @classmethod
- def _int_it(cls, val):
- try:
- num = int(val)
- except ValueError:
- num = 0
- return num
-
- @classmethod
- def _bool_it(cls, val):
- if isinstance(val, str):
- if re.match("^\s*(?i)(true)", val):
- return True
- elif re.match("^\s*(?i)(false)", val):
- return False
- return True if cls._int_it(val) else False