docs/main/GettingStarted.rst | 2 - moksha/exc.py | 3 + moksha/lib/helpers.py | 63 +++++++++++++++++++++++++++++++--------- moksha/middleware/middleware.py | 24 +++++++-------- 4 files changed, 66 insertions(+), 26 deletions(-)
New commits: commit 37608c9f46d03284bdf8e57a15ef1852872e4cd9 Author: Luke Macken lmacken@redhat.com Date: Tue Feb 17 18:29:54 2009 -0500
MokshaMiddleware.load_configs improvements and refactoring.
- Ensure we do not try and load the same configuration twice - Ensure we load Moksha's configuration - Ensure we can handle Moksha's configuration living in various locations.
diff --git a/moksha/middleware/middleware.py b/moksha/middleware/middleware.py index 4c3ccc9..ea60286 100644 --- a/moksha/middleware/middleware.py +++ b/moksha/middleware/middleware.py @@ -35,7 +35,8 @@ from sqlalchemy import create_engine from feedcache.cache import Cache
from moksha.exc import ApplicationNotFound, MokshaException -from moksha.lib.helpers import defaultdict +from moksha.lib.helpers import (defaultdict, get_moksha_config_path, + get_main_app_config_path) from moksha.wsgiapp import MokshaAppDispatcher
log = logging.getLogger(__name__) @@ -270,12 +271,18 @@ class MokshaMiddleware(object): where it is being run as WSGI middleware in a different environment.
""" - moksha_conf = os.path.abspath(__file__ + '/../../../') - for app in [{'path': moksha_conf}] + moksha.apps.values(): + config_paths = set() + moksha_config_path = os.path.dirname(get_moksha_config_path()) + main_app_config_path = os.path.dirname(get_main_app_config_path()) + for app in [{'path': moksha_config_path}] + moksha.apps.values(): + if app['path'] != main_app_config_path and \ + app['path'] not in config_paths: + config_paths.add(app['path']) + for config_path in config_paths: for configfile in ('production.ini', 'development.ini'): - confpath = os.path.join(app['path'], configfile) + confpath = os.path.join(config_path, configfile) if os.path.exists(confpath): - log.debug('Loading configuration: %s' % confpath) + log.info('Loading configuration: %s' % confpath) conf = appconfig('config:' + confpath) for entry in conf.global_conf: if entry.startswith('_'):
commit 278e4d4f693633ffb2c557f20c6ef938c185072e Author: Luke Macken lmacken@redhat.com Date: Tue Feb 17 18:29:22 2009 -0500
Add get_moksha_config_path and get_main_app_config_path methods to our helpers
diff --git a/moksha/exc.py b/moksha/exc.py index 442f131..ee5f3eb 100644 --- a/moksha/exc.py +++ b/moksha/exc.py @@ -28,3 +28,6 @@ class WidgetNotFound(MokshaException):
class CacheBackendException(MokshaException): pass + +class MokshaConfigNotFound(MokshaException): + pass diff --git a/moksha/lib/helpers.py b/moksha/lib/helpers.py index 8d19fcb..10768e4 100644 --- a/moksha/lib/helpers.py +++ b/moksha/lib/helpers.py @@ -3,21 +3,21 @@ import pylons import uuid import simplejson as json import re - -from webhelpers import date, feedgenerator, html, number, misc, text - -from repoze.what.predicates import (Not, Predicate, All, Any, has_all_permissions, - has_any_permission, has_permission, - in_all_groups, in_any_group, in_group, - is_user, not_anonymous) - -from repoze.what.authorize import check_authorization, NotAuthorizedError +import os +import logging
from webob import Request - from decorator import decorator +from webhelpers import date, feedgenerator, html, number, misc, text +from repoze.what.authorize import check_authorization, NotAuthorizedError +from repoze.what.predicates import (Not, Predicate, All, Any, + has_all_permissions, has_any_permission, + has_permission, in_all_groups, in_any_group, + in_group, is_user, not_anonymous)
+from moksha.exc import MokshaConfigNotFound
+log = logging.getLogger(__name__) scrub_filter = re.compile('[^_a-zA-Z0-9-]')
def _update_params(params, d): @@ -516,13 +516,39 @@ def cache_rendered(func, *args, **kwargs):
def in_full_moksha_stack(): - """ Figure out if we are running Moksha as WSGI middleware, or in our full stack. - - :returns True: If we are currently running in Moksha's full WSGI stack - :returns False: If are are only running Moksha as WSGI middleware + """ + Figure out if we are running Moksha as WSGI middleware, or in our full stack. + :returns: True if we are currently running in Moksha's full WSGI stack, + False if we are running Moksha only as WSGI middleware. """ try: - from pylons import config - return config.get('app_conf', {}).get('package', 'notmoksha') == 'moksha' + return pylons.config['app_conf']['package'] == 'moksha' except: return False + + +def get_main_app_config_path(): + """ + :returns: The path to the main applications configuratoin file + """ + try: + return pylons.config['__file__'] + except: + log.error('Cannot find main applications config file in ' + 'pylons.config["__file__"]') + + +def get_moksha_config_path(): + """ + :returns: The path to Moksha's configuration file. + """ + if in_full_moksha_stack(): + return get_main_app_config_path() + else: + for config_file in ('production.ini', 'development.ini'): + for config_path in ('/etc/moksha/', __file__ + '/../../../'): + cfg = os.path.join(os.path.abspath(config_path), config_file) + if os.path.isfile(cfg): + return cfg + + raise MokshaConfigNotFound('Cannot find moksha configuration file!')
commit 941844a524c82710c69795b53a660fd287d59efd Author: Luke Macken lmacken@redhat.com Date: Tue Feb 17 17:43:10 2009 -0500
Add a moksha.lib.helpers.is_full_moksha_stack() method to figure out if we are running as middleware, or using the full Moksha stack.
diff --git a/moksha/lib/helpers.py b/moksha/lib/helpers.py index fed408b..8d19fcb 100644 --- a/moksha/lib/helpers.py +++ b/moksha/lib/helpers.py @@ -513,3 +513,16 @@ def cache_rendered(func, *args, **kwargs): content = func(*args, **kwargs) cache_rendered_data(content) return content + + +def in_full_moksha_stack(): + """ Figure out if we are running Moksha as WSGI middleware, or in our full stack. + + :returns True: If we are currently running in Moksha's full WSGI stack + :returns False: If are are only running Moksha as WSGI middleware + """ + try: + from pylons import config + return config.get('app_conf', {}).get('package', 'notmoksha') == 'moksha' + except: + return False
commit c40d000eb5f180cce58b6da540b1cf23e276f8ea Author: Luke Macken lmacken@redhat.com Date: Tue Feb 17 17:42:53 2009 -0500
Clean up our clean_rendered decorator
diff --git a/moksha/lib/helpers.py b/moksha/lib/helpers.py index 4dd070d..fed408b 100644 --- a/moksha/lib/helpers.py +++ b/moksha/lib/helpers.py @@ -511,7 +511,5 @@ def cache_rendered_data(data): @decorator def cache_rendered(func, *args, **kwargs): content = func(*args, **kwargs) - if pylons.g.cache and \ - pylons.request.environ.get('HTTP_X_FORWARDED_PROTO'): - pylons.g.cache.set(pylons.request.path_qs, str(content)) + cache_rendered_data(content) return content
commit ac96b1df5f7fc982fb562712d73f907a7a8a6858 Author: Luke Macken lmacken@redhat.com Date: Tue Feb 17 17:41:37 2009 -0500
Add a few more deps to our initial dependency tree
diff --git a/docs/main/GettingStarted.rst b/docs/main/GettingStarted.rst index 3a7371b..f865d07 100644 --- a/docs/main/GettingStarted.rst +++ b/docs/main/GettingStarted.rst @@ -24,7 +24,7 @@ You'll need the `virtualenv http://pypi.python.org/pypi/virtualenv`_ package.
.. code-block:: bash
- # yum -y install python-virtualenv pysvn mercurial + # yum -y install python-virtualenv pysvn mercurial PyOpenSSL python-memcached
The `start-moksha` script mentioned below should install all of the necessary dependencies. However, it will attempt to compile a few things, such as lxml. So, you may need to install some additional dependencies like `libxml2` and `libxslt` in order to build it. If you're using yum, you can easily install all of the build requirements by doing:
commit 308204e683d120f5e711c2dd22c0d690b5bbf875 Author: Luke Macken lmacken@redhat.com Date: Tue Feb 17 15:59:54 2009 -0500
No need to load the model for WSGI mounted apps
diff --git a/moksha/middleware/middleware.py b/moksha/middleware/middleware.py index 156a7ba..4c3ccc9 100644 --- a/moksha/middleware/middleware.py +++ b/moksha/middleware/middleware.py @@ -149,13 +149,6 @@ class MokshaMiddleware(object): 'path': app_path, 'model': None, } - try: - model = __import__('%s.model' % app_entry.name, - globals(), locals(), - [app_entry.name]) - moksha.apps[app_entry.name]['model'] = model - except ImportError: - pass
def load_widgets(self): log.info('Loading moksha widgets')
moksha-commits@lists.fedorahosted.org