Setup the plugin from an application.
345280
def setup(self, app):
        
        super().setup(app)

        if isinstance(self.cfg.template_folders, str):
            self.cfg.template_folders = [self.cfg.template_folders]

        else:
            self.cfg.template_folders = list(self.cfg.template_folders)

        self.ctx_provider(lambda: {'app': self.app})
        self.env = Environment(debug=app.cfg.DEBUG, **self.cfg)
1118490
def init_app(self, app, **kwargs):
        """"""
        self.kwargs.update(kwargs)
        self.settings = self.dynaconf_instance or LazySettings(**self.kwargs)
        app.config = self.make_config(app)
        app.dynaconf = self.settings
1087314
def setup(self, app):
        ''' '''
        for other in app.plugins:
            if not isinstance(other, SQLAlchemyPlugin):
                continue
            if other.keyword == self.keyword:
                raise bottle.PluginError("Found another SQLAlchemy plugin with "\
                                  "conflicting settings (non-unique keyword).")
            elif other.name == self.name:
                self.name += '_%s' % self.keyword
        if self.create and not self.metadata:
            raise bottle.PluginError('Define metadata value to create database.')
369041
def setup(self, app):
        '''
        
        '''
        for other in app.plugins:
            if not isinstance(other, MySQLPlugin):
                continue
            if other.keyword == self.keyword:
                raise PluginError("Found another mysql plugin with conflicting settings (non-unique keyword).")
            elif other.name == self.name:
                self.name += '_%s' % self.keyword
321473
def init_app(self, app):
        """"""
        if self.module:
            app.config.from_object(self.module)
1219725
def setup(self, app):
        """"""
        super().setup(app)
        self.cfg.port = int(self.cfg.port)
        self.cfg.db = int(self.cfg.db)
        self.cfg.poolsize = int(self.cfg.poolsize)
621292
def setup(app):
    """"""
    app.connect('html-page-context', add_html_link)
    app.connect('build-finished', create_sitemap)
    app.set_translator('html', HTMLTranslator)
    app.sitemap_links = []
941111
def start_plugin(file_path=None):
    """"""
    if os.getenv('CONFIG_PATH'):
        file_path = os.getenv('CONFIG_PATH')
    else:
        file_path = file_path
    if file_path is not None:
        config = parse_config(file_path)
        plugin_instance = load_plugin(config)
    else:
        plugin_instance = load_plugin
    return plugin_instance
218948
def setup(self, app):
        
        super().setup(app)

        self.handlers = OrderedDict()

        # Connect admin templates
        app.ps.jinja2.cfg.template_folders.append(op.join(PLUGIN_ROOT, 'templates'))

        @app.ps.jinja2.filter
        def admtest(value, a, b=None):
            return a if value else b

        @app.ps.jinja2.filter
        def admeq(a, b, result=True):
            return result if a == b else not result

        @app.ps.jinja2.register
        def admurl(request, prefix):
            qs = {k: v for k, v in request.query.items() if not k.startswith(prefix)}
            if not qs:
                qs = {'ap': 0}
            return "%s?%s" % (request.path, urlparse.urlencode(qs))

        if self.cfg.name is None:
            self.cfg.name = "%s admin" % app.name.title()

        # Register a base view
        if not callable(self.cfg.home):

            def admin_home(request):
                yield from self.authorize(request)
                return app.ps.jinja2.render(self.cfg.template_home, active=None)

            self.cfg.home = admin_home

        app.register(self.cfg.prefix)(self.cfg.home)

        if not self.cfg.i18n:
            app.ps.jinja2.env.globals.update({
                '_': lambda s: s,
                'gettext': lambda s: s,
                'ngettext': lambda s, p, n: (n != 1 and (p,) or (s,))[0],
            })

            return

        if 'babel' not in app.ps or not isinstance(app.ps.babel, BPlugin):
            raise PluginException(
                'Plugin `%s` requires for plugin `%s` to be installed to the application.' % (
                    self.name, BPlugin))

        # Connect admin locales
        app.ps.babel.cfg.locales_dirs.append(op.join(PLUGIN_ROOT, 'locales'))
        if not app.ps.babel.locale_selector_func:
            app.ps.babel.locale_selector_func = app.ps.babel.select_locale_by_request
552746
def set_plugins(self, input_plugins):
        """"""
        header = "glances_"
        for item in input_plugins:
            # Import the plugin
            try:
                plugin = __import__(header + item)
            except ImportError:
                # Server plugin can not be imported from the client side
                logger.error("Can not import {} plugin. Please upgrade your Glances client/server version.".format(item))
            else:
                # Add the plugin to the dictionary
                # The key is the plugin name
                # for example, the file glances_xxx.py
                # generate self._plugins_list["xxx"] = ...
                logger.debug("Server uses {} plugin".format(item))
                self._plugins[item] = plugin.Plugin(args=self.args)
        # Restoring system path
        sys.path = sys_path
1099662
def setup(self, options=None, extractor=None):
        
        # Get our programmatic options
        self._util.use_options(options, extractor)

        # Overwrite non defaults in self.values with values from config
        self._util.use_config_file()
23751
def add_plugin(self, plugin):
        
        self.plugin_by_name[plugin.get_plugin_name()] = plugin
        self.plugins.append(plugin)
437575
def _setup(app, *, schema,  title=None, app_key=APP_KEY, db=None):
    """"""

    admin = web.Application(loop=app.loop)
    app[app_key] = admin
    loader = jinja2.FileSystemLoader([TEMPLATES_ROOT, ])
    aiohttp_jinja2.setup(admin, loader=loader, app_key=TEMPLATE_APP_KEY)

    if title:
        schema.title = title

    resources = [
        init(db, info['table'], url=info['url'])
        for init, info in schema.resources
    ]

    admin_handler = AdminOnRestHandler(
        admin,
        resources=resources,
        loop=app.loop,
        schema=schema,
    )

    admin['admin_handler'] = admin_handler
    setup_admin_on_rest_handlers(admin, admin_handler)

    return admin
899973
def create_app(config='udata.settings.Defaults', override=None,
               init_logging=init_logging):
    ''''''
    app = UDataApp(APP_NAME)
    app.config.from_object(config)

    settings = os.environ.get('UDATA_SETTINGS', join(os.getcwd(), 'udata.cfg'))
    if exists(settings):
        app.settings_file = settings  # Keep track of loaded settings for diagnostic
        app.config.from_pyfile(settings)

    if override:
        app.config.from_object(override)

    # Loads defaults from plugins
    for pkg in entrypoints.get_roots(app):
        if pkg == 'udata':
            continue  # Defaults are already loaded
        module = '{}.settings'.format(pkg)
        if pkgutil.find_loader(module):
            settings = pkgutil.get_loader(module)
            for key, default in settings.__dict__.items():
                app.config.setdefault(key, default)

    app.json_encoder = UDataJsonEncoder

    app.debug = app.config['DEBUG'] and not app.config['TESTING']

    app.wsgi_app = ProxyFix(app.wsgi_app)

    init_logging(app)
    register_extensions(app)

    return app
1363873
def install_plugin(username, repo):
    """"""
    print("Installing plugin from " + username + "/" + repo)

    pip.main(['install', '-U', "git+git://github.com/" +
              username + "/" + repo + ".git"])
945825
def add_plugin(plugin, directory=None):
    """"""
    repo = require_repo(directory)
    plugins = get_value(repo, 'plugins', expect_type=dict)
    if plugin in plugins:
        return False

    plugins[plugin] = {}
    set_value(repo, 'plugins', plugins)
    return True
866587
def setup(self, app):
        """"""
        super(Plugin, self).setup(app)

        if 'jinja2' not in app.plugins:
            raise PluginException('The plugin requires Muffin-Jinja2 plugin installed.')

        self.cfg.prefix = self.cfg.prefix.rstrip('/') + '/'
        self.cfg.exclude.append(self.cfg.prefix)

        # Setup debugtoolbar templates
        app.ps.jinja2.cfg.template_folders.append(op.join(PLUGIN_ROOT, 'templates'))

        self.cfg.panels += list(self.cfg.additional_panels)
        panels_ = []
        for panel in self.cfg.panels:
            if isinstance(panel, str):
                mod, _, panel = panel.partition(':')
                mod = importlib.import_module(mod)
                panel = eval(panel or 'DebugPanel', mod.__dict__)
            panels_.append(panel)
        self.cfg.panels = panels_

        # Setup debugtoolbar static files
        app.router.register_route(StaticRoute(
            'debugtoolbar.static',
            self.cfg.prefix + 'static/',
            op.join(PLUGIN_ROOT, 'static')))

        app.register(self.cfg.prefix + 'sse', name='debugtoolbar.sse')(self.sse)
        app.register(
            self.cfg.prefix + 'exception', name='debugtoolbar.exception')(self.exception)
        app.register(
            self.cfg.prefix + 'execute', name='debugtoolbar.execute')(self.execute)
        app.register(
            self.cfg.prefix + 'source', name='debugtoolbar.source')(self.source)
        app.register(
            self.cfg.prefix.rstrip('/'),
            self.cfg.prefix,
            self.cfg.prefix + '{request_id}', name='debugtoolbar.request')(self.view)

        app['debugtoolbar'] = {}
        app['debugtoolbar']['pdbt_token'] = uuid.uuid4().hex
        self.history = app['debugtoolbar']['history'] = utils.History(50)
        self.exceptions = app['debugtoolbar']['exceptions'] = utils.History(50)
        self.frames = app['debugtoolbar']['frames'] = utils.History(100)