Skip to content

Commit

Permalink
Use Configurator() instead of deprecated make_app()
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Rossi committed Dec 2, 2011
1 parent c655060 commit a4fed6b
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions karlserve/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from persistent.mapping import PersistentMapping

from pyramid_zcml import make_app as bfg_make_app
from pyramid.config import Configurator
from repoze.depinj import lookup
from repoze.retry import Retry
from repoze.tm import TM as make_tm
Expand All @@ -30,6 +30,7 @@
from karlserve.log import set_subsystem
from karlserve.textindex import KarlPGTextIndex

import karl.includes
from karl.bootstrap.interfaces import IBootstrapper
from karl.bootstrap.bootstrap import populate
from karl.errorlog import error_log_middleware
Expand Down Expand Up @@ -302,15 +303,15 @@ def _get_config(global_config, uri):


def make_karl_instance(name, global_config, uri):
config = _get_config(global_config, uri)
settings = _get_config(global_config, uri)

def appmaker(folder, name='site'):
if name not in folder:
bootstrapper = queryUtility(IBootstrapper, default=populate)
bootstrapper(folder, name)

# Use pgtextindex
if 'pgtextindex.dsn' in config:
if 'pgtextindex.dsn' in settings:
site = folder.get(name)
index = lookup(KarlPGTextIndex)(get_weighted_textrepr)
site.catalog['texts'] = index
Expand All @@ -319,7 +320,7 @@ def appmaker(folder, name='site'):

return folder[name]

# paster app config callback
# paster app settings callback
get_root = PersistentApplicationFinder(uri, appmaker)
def closer():
db = get_root.db
Expand All @@ -330,17 +331,25 @@ def closer():
# Subsystem for logging
set_subsystem('karl')

# Make BFG app
pkg_name = config.get('package', None)
# Make Pyramid app
pkg_name = settings.get('package', None)
if pkg_name is not None:
__import__(pkg_name)
package = sys.modules[pkg_name]
app = bfg_make_app(get_root, package, options=config)
filename = 'configure.zcml'
else:
filename = 'karl.includes:standalone.zcml'
app = bfg_make_app(get_root, filename=filename, options=config)

app.config = config
package = karl.includes
filename = 'standalone.zcml'
config = Configurator(package=package, settings=settings,
root_factory=get_root, autocommit=True)
config.begin()
config.hook_zca()
config.include('pyramid_zcml')
config.load_zcml(filename)
config.end()

app = config.make_wsgi_app()
app.config = settings
app.uri = uri
app.close = closer

Expand Down

0 comments on commit a4fed6b

Please sign in to comment.