From cc9bf9f2df99b86b87ac4e537c1fb21b8cbdd4b3 Mon Sep 17 00:00:00 2001 From: Goffi Date: Wed, 27 Aug 2014 01:27:05 +0200 Subject: [PATCH] core (constants): Bool method allow to convert from python bool to string constant for true/false (in both directions) --- src/core/constants.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/core/constants.py b/src/core/constants.py index 27605ffa..6529a619 100644 --- a/src/core/constants.py +++ b/src/core/constants.py @@ -186,3 +186,8 @@ class Const(object): # XXX: we use a classmethod so we can use Const inheritance to change default options return(cls.LOG_OPT_COLORS, cls.LOG_OPT_LEVEL, cls.LOG_OPT_FORMAT, cls.LOG_OPT_LOGGER, cls.LOG_OPT_OUTPUT) + @classmethod + def bool(cls, value): + if isinstance(value, bool): + return cls.BOOL_TRUE if value else cls.BOOL_FALSE + return value.lower() == cls.BOOL_TRUE