Add the staticdirector stuff to the mediagoblin wsgi app.
This commit is contained in:
parent
dae6add99e
commit
582c4d5fb2
@ -5,6 +5,7 @@ debug = true
|
|||||||
use = egg:Paste#urlmap
|
use = egg:Paste#urlmap
|
||||||
/ = mediagoblin
|
/ = mediagoblin
|
||||||
/mgoblin_media/ = publicstore_serve
|
/mgoblin_media/ = publicstore_serve
|
||||||
|
/mgoblin_static/ = mediagoblin_static
|
||||||
|
|
||||||
[app:mediagoblin]
|
[app:mediagoblin]
|
||||||
use = egg:mediagoblin#app
|
use = egg:mediagoblin#app
|
||||||
@ -12,6 +13,7 @@ filter-with = beaker
|
|||||||
queuestore_base_dir = %(here)s/user_dev/media/queue
|
queuestore_base_dir = %(here)s/user_dev/media/queue
|
||||||
publicstore_base_dir = %(here)s/user_dev/media/public
|
publicstore_base_dir = %(here)s/user_dev/media/public
|
||||||
publicstore_base_url = /mgoblin_media/
|
publicstore_base_url = /mgoblin_media/
|
||||||
|
direct_remote_path = /mgoblin_static/
|
||||||
## Uncomment this to put some user-overriding templates here
|
## Uncomment this to put some user-overriding templates here
|
||||||
#local_templates = %(here)s/user_dev/templates/
|
#local_templates = %(here)s/user_dev/templates/
|
||||||
|
|
||||||
@ -19,6 +21,10 @@ publicstore_base_url = /mgoblin_media/
|
|||||||
use = egg:Paste#static
|
use = egg:Paste#static
|
||||||
document_root = %(here)s/user_dev/media/public
|
document_root = %(here)s/user_dev/media/public
|
||||||
|
|
||||||
|
[app:mediagoblin_static]
|
||||||
|
use = egg:Paste#static
|
||||||
|
document_root = %(here)s/mediagoblin/static/
|
||||||
|
|
||||||
[server:main]
|
[server:main]
|
||||||
use = egg:Paste#http
|
use = egg:Paste#http
|
||||||
host = 127.0.0.1
|
host = 127.0.0.1
|
||||||
|
@ -20,7 +20,7 @@ import routes
|
|||||||
import mongokit
|
import mongokit
|
||||||
from webob import Request, exc
|
from webob import Request, exc
|
||||||
|
|
||||||
from mediagoblin import routing, util, models, storage
|
from mediagoblin import routing, util, models, storage, staticdirect
|
||||||
|
|
||||||
|
|
||||||
class Error(Exception): pass
|
class Error(Exception): pass
|
||||||
@ -33,6 +33,7 @@ class MediaGoblinApp(object):
|
|||||||
"""
|
"""
|
||||||
def __init__(self, connection, database_path,
|
def __init__(self, connection, database_path,
|
||||||
public_store, queue_store,
|
public_store, queue_store,
|
||||||
|
staticdirector,
|
||||||
user_template_path=None):
|
user_template_path=None):
|
||||||
# Get the template environment
|
# Get the template environment
|
||||||
self.template_env = util.get_jinja_env(user_template_path)
|
self.template_env = util.get_jinja_env(user_template_path)
|
||||||
@ -49,10 +50,14 @@ class MediaGoblinApp(object):
|
|||||||
# set up routing
|
# set up routing
|
||||||
self.routing = routing.get_mapper()
|
self.routing = routing.get_mapper()
|
||||||
|
|
||||||
|
# set up staticdirector tool
|
||||||
|
self.staticdirector = staticdirector
|
||||||
|
|
||||||
def __call__(self, environ, start_response):
|
def __call__(self, environ, start_response):
|
||||||
request = Request(environ)
|
request = Request(environ)
|
||||||
path_info = request.path_info
|
path_info = request.path_info
|
||||||
|
|
||||||
|
## Routing / controller loading stuff
|
||||||
route_match = self.routing.match(path_info)
|
route_match = self.routing.match(path_info)
|
||||||
|
|
||||||
# No matching page?
|
# No matching page?
|
||||||
@ -75,11 +80,13 @@ class MediaGoblinApp(object):
|
|||||||
controller = util.import_component(route_match['controller'])
|
controller = util.import_component(route_match['controller'])
|
||||||
request.start_response = start_response
|
request.start_response = start_response
|
||||||
|
|
||||||
|
## Attach utilities to the request object
|
||||||
request.matchdict = route_match
|
request.matchdict = route_match
|
||||||
request.app = self
|
request.app = self
|
||||||
request.template_env = self.template_env
|
request.template_env = self.template_env
|
||||||
request.urlgen = routes.URLGenerator(self.routing, environ)
|
request.urlgen = routes.URLGenerator(self.routing, environ)
|
||||||
request.db = self.db
|
request.db = self.db
|
||||||
|
request.staticdirect = self.staticdirector
|
||||||
# Do we really want to load this via middleware? Maybe?
|
# Do we really want to load this via middleware? Maybe?
|
||||||
request.session = request.environ['beaker.session']
|
request.session = request.environ['beaker.session']
|
||||||
util.setup_user_in_request(request)
|
util.setup_user_in_request(request)
|
||||||
@ -98,9 +105,22 @@ def paste_app_factory(global_config, **kw):
|
|||||||
queue_store = storage.storage_system_from_paste_config(
|
queue_store = storage.storage_system_from_paste_config(
|
||||||
kw, 'queuestore')
|
kw, 'queuestore')
|
||||||
|
|
||||||
|
# Set up the staticdirect system
|
||||||
|
if kw.has_key('direct_remote_path'):
|
||||||
|
staticdirector = staticdirect.RemoteStaticDirect(
|
||||||
|
kw['direct_remote_path'].strip())
|
||||||
|
elif kw.has_key('direct_remote_paths'):
|
||||||
|
staticdirector = staticdirect.MultiRemoteStaticDirect(
|
||||||
|
dict([line.strip().split(' ', 1)
|
||||||
|
for line in kw['direct_remote_paths'].strip().splitlines()]))
|
||||||
|
else:
|
||||||
|
raise ImproperlyConfigured(
|
||||||
|
"One of direct_remote_path or direct_remote_paths must be provided")
|
||||||
|
|
||||||
mgoblin_app = MediaGoblinApp(
|
mgoblin_app = MediaGoblinApp(
|
||||||
connection, kw.get('db_name', 'mediagoblin'),
|
connection, kw.get('db_name', 'mediagoblin'),
|
||||||
public_store=public_store, queue_store=queue_store,
|
public_store=public_store, queue_store=queue_store,
|
||||||
|
staticdirector=staticdirector,
|
||||||
user_template_path=kw.get('local_templates'))
|
user_template_path=kw.get('local_templates'))
|
||||||
|
|
||||||
return mgoblin_app
|
return mgoblin_app
|
||||||
|
Loading…
x
Reference in New Issue
Block a user