You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2015/11/12 21:18:28 UTC

allura git commit: [#8015] for activitystream, convert string bools to actual bools

Repository: allura
Updated Branches:
  refs/heads/db/8015 [created] 3c3d3ed51


[#8015] for activitystream, convert string bools to actual bools


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/3c3d3ed5
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/3c3d3ed5
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/3c3d3ed5

Branch: refs/heads/db/8015
Commit: 3c3d3ed5188604b87721b27be3eb8200f1af3bbf
Parents: 7282b40
Author: Dave Brondsema <da...@brondsema.net>
Authored: Thu Nov 12 15:18:17 2015 -0500
Committer: Dave Brondsema <da...@brondsema.net>
Committed: Thu Nov 12 15:18:17 2015 -0500

----------------------------------------------------------------------
 Allura/allura/command/base.py       |  6 +++---
 Allura/allura/config/middleware.py  |  2 +-
 Allura/allura/lib/helpers.py        | 23 +++++++++++++++++++++++
 Allura/allura/tests/test_helpers.py | 10 ++++++++++
 Allura/allura/websetup/schema.py    |  4 +++-
 5 files changed, 40 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/3c3d3ed5/Allura/allura/command/base.py
----------------------------------------------------------------------
diff --git a/Allura/allura/command/base.py b/Allura/allura/command/base.py
index 3d619fc..66b46d5 100644
--- a/Allura/allura/command/base.py
+++ b/Allura/allura/command/base.py
@@ -29,7 +29,7 @@ import activitystream
 import ming
 from allura.config.environment import load_environment
 from allura.lib.decorators import task
-from allura.lib.helpers import iter_entry_points
+from allura.lib import helpers as h
 
 log = None
 
@@ -103,14 +103,14 @@ class Command(command.Command):
             M = model
             ming.configure(**conf)
             if asbool(conf.get('activitystream.recording.enabled', False)):
-                activitystream.configure(**conf)
+                activitystream.configure(**h.convert_bools(conf, prefix='activitystream.'))
             pylons.tmpl_context.user = M.User.anonymous()
         else:
             # Probably being called from another script (websetup, perhaps?)
             log = logging.getLogger('allura.command')
             conf = pylons.config
         self.tools = pylons.app_globals.entry_points['tool'].values()
-        for ep in iter_entry_points('allura.command_init'):
+        for ep in h.iter_entry_points('allura.command_init'):
             log.info('Running command_init for %s', ep.name)
             ep.load()(conf)
         log.info('Loaded tools')

http://git-wip-us.apache.org/repos/asf/allura/blob/3c3d3ed5/Allura/allura/config/middleware.py
----------------------------------------------------------------------
diff --git a/Allura/allura/config/middleware.py b/Allura/allura/config/middleware.py
index 5ce50a3..fd137c2 100644
--- a/Allura/allura/config/middleware.py
+++ b/Allura/allura/config/middleware.py
@@ -99,7 +99,7 @@ def _make_core_app(root, global_conf, full_stack=True, **app_conf):
 
     # Configure ActivityStream
     if asbool(app_conf.get('activitystream.recording.enabled', False)):
-        activitystream.configure(**app_conf)
+        activitystream.configure(**h.convert_bools(app_conf, prefix='activitystream.'))
 
     # Configure EW variable provider
     ew.render.TemplateEngine.register_variable_provider(get_tg_vars)

http://git-wip-us.apache.org/repos/asf/allura/blob/3c3d3ed5/Allura/allura/lib/helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index 72c64ad..93c0d6f 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -348,6 +348,29 @@ def vardec(fun):
     return fun
 
 
+def convert_bools(conf, prefix=''):
+    '''
+    For a given dict, automatically convert any true/false string values into bools.
+    Only applies to keys starting with the prefix.
+
+    :param dict conf:
+    :param str prefix:
+    :return: dict
+    '''
+    def convert_value(val):
+        if isinstance(val, basestring):
+            if val.strip().lower() == 'true':
+                return True
+            elif val.strip().lower() == 'false':
+                return False
+        return val
+
+    return {
+        k: (convert_value(v) if k.startswith(prefix) else v)
+        for k, v in conf.iteritems()
+    }
+
+
 def nonce(length=4):
     return sha1(ObjectId().binary + os.urandom(10)).hexdigest()[:length]
 

http://git-wip-us.apache.org/repos/asf/allura/blob/3c3d3ed5/Allura/allura/tests/test_helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_helpers.py b/Allura/allura/tests/test_helpers.py
index 8f2c01e..296a7c3 100644
--- a/Allura/allura/tests/test_helpers.py
+++ b/Allura/allura/tests/test_helpers.py
@@ -564,6 +564,7 @@ class TestIterEntryPoints(TestCase):
                                 'Multiple entry points with name "myapp".',
                                 list, h.iter_entry_points('allura'))
 
+
 def test_get_user_status():
     user = M.User.by_username('test-admin')
     assert_equals(h.get_user_status(user), 'enabled')
@@ -576,3 +577,12 @@ def test_get_user_status():
 
     user = Mock(disabled=True, pending=True)  # not an expected combination
     assert_equals(h.get_user_status(user), 'disabled')
+
+
+def test_convert_bools():
+    assert_equals(h.convert_bools({'foo': 'bar', 'baz': 'false', 'abc': 0, 'def': 1, 'ghi': True}),
+                  {'foo': 'bar', 'baz': False, 'abc': 0, 'def': 1, 'ghi': True})
+    assert_equals(h.convert_bools({'foo': 'true', 'baz': ' TRUE '}),
+                  {'foo': True, 'baz': True})
+    assert_equals(h.convert_bools({'foo': 'true', 'baz': ' TRUE '}, prefix='ba'),
+                  {'foo': 'true', 'baz': True})
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/allura/blob/3c3d3ed5/Allura/allura/websetup/schema.py
----------------------------------------------------------------------
diff --git a/Allura/allura/websetup/schema.py b/Allura/allura/websetup/schema.py
index d25128e..88c57a4 100644
--- a/Allura/allura/websetup/schema.py
+++ b/Allura/allura/websetup/schema.py
@@ -27,6 +27,8 @@ import pylons
 from paste.deploy.converters import asbool
 from paste.registry import Registry
 
+from allura.lib import helpers as h
+
 log = logging.getLogger(__name__)
 REGISTRY = Registry()
 
@@ -42,7 +44,7 @@ def setup_schema(command, conf, vars):
     REGISTRY.register(allura.credentials, allura.lib.security.Credentials())
     ming.configure(**conf)
     if asbool(conf.get('activitystream.recording.enabled', False)):
-        activitystream.configure(**conf)
+        activitystream.configure(**h.convert_bools(conf, prefix='activitystream.'))
     # Nothing to do
     log.info('setup_schema called')