Example #1
0
def _load():
    """Imports the files from the plugins directories and loads templates."""
    from infogami.utils import macro, template
    global plugins

    plugins = [_make_plugin('core')]

    if config.plugins is not None:
        plugins += [_make_plugin(p) for p in config.plugins]
    else:
        for p in config.plugin_path:
            m = __import__(p)
            root = os.path.dirname(m)
            plugins += _list_plugins(root)

    if config.plugin_modules is not None:
        plugins += [
            _make_plugin_module(name) for name in config.plugin_modules
        ]

    for plugin in plugins:
        template.load_templates(plugin.path, lazy=True)
        macro.load_macros(plugin.path, lazy=True)
        i18n.load_strings(plugin.path)
        __import__(plugin.module + '.code', globals(), locals(), ['plugins'])

    features.set_feature_flags(config.get("features", {}))
Example #2
0
def setup():
    setup_logging()

    logger = logging.getLogger("openlibrary")
    logger.info("Application init")

    for p in old_plugins:
        logger.info("loading plugin %s", p)
        modname = "openlibrary.plugins.%s.code" % p
        path = "openlibrary/plugins/" + p
        template.load_templates(path, lazy=True)
        macro.load_macros(path, lazy=True)
        i18n.load_strings(path)
        __import__(modname, globals(), locals(), ['plugins'])

    delegate.plugins += [
        delegate._make_plugin_module('openlibrary.plugins.' + name)
        for name in old_plugins
    ]

    load_views()

    # load actions
    from . import actions

    logger.info("loading complete.")
Example #3
0
def setup():
    for p in old_plugins:
        modname = "openlibrary.plugins.%s.code" % p
        print "loading", p, modname
        path = "openlibrary/plugins/" + p
        template.load_templates(path, lazy=True)
        macro.load_macros(path, lazy=True)
        i18n.load_strings(path)
        __import__(modname, globals(), locals(), ['plugins'])
Example #4
0
def pytest_funcarg__render_template(request):
    """Utility to test templates.
    """
    template.load_templates("openlibrary/plugins/openlibrary")
    template.load_templates("openlibrary/plugins/upstream")

    #TODO: call setup on upstream and openlibrary plugins to
    # load all globals.
    web.template.Template.globals["_"] = gettext
    web.template.Template.globals.update(helpers.helpers)

    web.ctx.env = web.storage()
    web.ctx.headers = []
    web.ctx.lang = "en"

    # ol_infobase.init_plugin call is failing when trying to import plugins.openlibrary.code.
    # monkeypatch to avoid that.
    from openlibrary.plugins import ol_infobase

    init_plugin = ol_infobase.init_plugin
    ol_infobase.init_plugin = lambda: None

    def undo():
        ol_infobase.init_plugin = init_plugin

    request.addfinalizer(undo)

    from openlibrary.plugins.openlibrary import code
    web.config.db_parameters = dict()
    code.setup_template_globals()

    def finalizer():
        template.disktemplates.clear()
        web.ctx.clear()

    request.addfinalizer(finalizer)

    def render(name, *a, **kw):
        as_string = kw.pop("as_string", True)
        d = render_template(name, *a, **kw)
        if as_string:
            return unicode(d)
        else:
            return d

    return render
Example #5
0
def pytest_funcarg__render_template(request):
    """Utility to test templates.
    """    
    template.load_templates("openlibrary/plugins/openlibrary")
    template.load_templates("openlibrary/plugins/upstream")
    
    #TODO: call setup on upstream and openlibrary plugins to 
    # load all globals.
    web.template.Template.globals["_"] = gettext
    web.template.Template.globals.update(helpers.helpers)

    web.ctx.env = web.storage()
    web.ctx.headers = []
    web.ctx.lang = "en"

    # ol_infobase.init_plugin call is failing when trying to import plugins.openlibrary.code.
    # monkeypatch to avoid that.
    from openlibrary.plugins import ol_infobase
    
    init_plugin = ol_infobase.init_plugin
    ol_infobase.init_plugin = lambda: None
    def undo():
        ol_infobase.init_plugin = init_plugin
    request.addfinalizer(undo)    
    
    from openlibrary.plugins.openlibrary import code
    web.config.db_parameters = dict()
    code.setup_template_globals()

    def finalizer():
        template.disktemplates.clear()
        web.ctx.clear()

    request.addfinalizer(finalizer)
    
    def render(name, *a, **kw):
        as_string = kw.pop("as_string", True)
        d = render_template(name, *a, **kw)
        if as_string:
            return unicode(d)
        else:
            return d
    return render
Example #6
0
def setup():
    setup_logging()

    logger = logging.getLogger("openlibrary")
    logger.info("Application init")

    for p in old_plugins:
        logger.info("loading plugin %s", p)
        modname = "openlibrary.plugins.%s.code" % p
        path = "openlibrary/plugins/" + p
        template.load_templates(path, lazy=True)
        macro.load_macros(path, lazy=True)
        i18n.load_strings(path)
        __import__(modname, globals(), locals(), ['plugins'])

    load_views()

    # load actions
    from . import actions

    logger.info("loading complete.")
Example #7
0
def setup():
    # load templates from this package so that they are available via render_template
    from infogami.utils import template
    template.load_templates(os.path.dirname(__file__))
Example #8
0
def setup():
    # load templates from this package so that they are available via render_template
    from infogami.utils import template
    template.load_templates(os.path.dirname(__file__))