From 7747b4c28c4d9ed596e72061f34261d6158efe17 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Thu, 25 Jul 2013 11:02:18 -0300 Subject: Add leap_check helper method, #3007 related issue. --- src/leap/common/check.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src') diff --git a/src/leap/common/check.py b/src/leap/common/check.py index e6b0b52..82da5ff 100644 --- a/src/leap/common/check.py +++ b/src/leap/common/check.py @@ -60,3 +60,20 @@ def leap_assert_type(var, expectedType): leap_assert(isinstance(var, expectedType), "Expected type %r instead of %r" % (expectedType, type(var))) + + +def leap_check(condition, message="", exception=Exception): + """ + Asserts the condition and displays the message if that's not + met. It also logs the error and its backtrace. + + :param condition: condition to check + :type condition: bool + :param message: message to display if the condition isn't met + :type message: str + :param exception: the exception to raise in case of condition being false. + :type exception: Exception + """ + if not condition: + logger.error(message) + raise exception(message) -- cgit v1.2.3