From 632d8ced904685953d38eec40b68ad03c34b2d3e Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauld.mccarthy@gmail.com>
Date: Wed, 25 May 2016 11:30:04 +0100
Subject: [PATCH] Convenience function to convert string to bool (for saved
 boolean settings).

---
 fsl/utils/settings.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/fsl/utils/settings.py b/fsl/utils/settings.py
index e3b759d47..8728ae0b5 100644
--- a/fsl/utils/settings.py
+++ b/fsl/utils/settings.py
@@ -32,6 +32,24 @@ should be the same as the identifier given to the OSX application bundle
 """
 
 
+def strToBool(s):
+    """Currently the ``settings`` module is not type aware, so boolean
+    values are saved as strings ``'True'`` or ``'False'``. This makes
+    conversion back to boolean a bit annoying, as ``'False'`` evaluates
+    to ``True``.
+
+    This function may be used for a more sensible `str` -> `bool`
+    conversion
+
+    .. note:: In the future, the ``settings`` module will hopefully be 
+              type-aware, so use of this function will no longer be necessary.
+    """
+    s = str(s).lower()
+    if   s == 'true':  return True
+    elif s == 'false': return False
+    else:              return bool(s) 
+
+
 def read(name, default=None):
     """Reads a setting with the given ``name``, return ``default`` if
     there is no setting called ``name``.
-- 
GitLab