Exemplo n.º 1
0
    def _plug_application(self, app_config, module_name, options):
        module = __import__(module_name, globals(), locals(), [
            'plugme', 'model', 'lib', 'helpers', 'controllers', 'bootstrap',
            'public', 'partials'
        ], -1)

        appid = options['appid']

        self.plugged['appids'][appid] = module_name
        self.plugged['modules'][module_name] = dict(appid=appid,
                                                    module_name=module_name,
                                                    module=module,
                                                    statics=None)

        if hasattr(module, 'model') and options.get('plug_models', True):
            models_adapter = ModelsAdapter(app_config, module.model, options)
            models_adapter.adapt_tables()
            models_adapter.init_model()

        if hasattr(module, 'helpers') and options.get('plug_helpers', True):
            try:
                app_helpers = app_config.package.lib.helpers
            except:
                app_helpers = None

            if app_helpers:
                setattr(app_helpers, module_name, module.helpers)

                if options.get('global_helpers', False):
                    for name, impl in inspect.getmembers(module.helpers):
                        if name.startswith('_'):
                            continue

                        if not hasattr(app_helpers, name):
                            setattr(app_helpers, name, impl)
                        else:
                            log.warning(
                                '%s helper already existing, skipping it' %
                                name)

        if hasattr(module, 'controllers') and options.get(
                'plug_controller', True):
            controllers_adapter = ControllersAdapter(app_config,
                                                     module.controllers,
                                                     options)
            app_config.register_hook('after_config',
                                     controllers_adapter.mount_controllers)

        if hasattr(module, 'bootstrap') and options.get(
                'plug_bootstrap', True):
            websetup_adapter = WebSetupAdapter(app_config, module, options)
            websetup_adapter.adapt_bootstrap()

        if hasattr(module, 'public') and options.get('plug_statics', True):
            statics_adapter = StaticsAdapter(app_config, module, options)
            statics_adapter.register_statics(module_name, self.plugged)
Exemplo n.º 2
0
    def _plug_application(self, app_config, module_name, options):
        #In some cases the application is reloaded causing the startup hook to trigger again,
        #avoid plugging things over and over in such case.
        if module_name in self.plugged['modules']:
            return

        module = __import__(module_name, globals(), locals(),
            ['plugme', 'model', 'lib', 'helpers', 'controllers', 'bootstrap', 'public', 'partials'],
            -1)

        appid = options['appid']

        self.plugged['appids'][appid] = module_name
        self.plugged['modules'][module_name] = dict(appid=appid, module_name=module_name, module=module, statics=None)

        if hasattr(module, 'model') and options.get('plug_models', True):
            models_adapter = ModelsAdapter(app_config, module.model, options)
            models_adapter.adapt_tables()
            models_adapter.init_model()

        if hasattr(module, 'helpers') and options.get('plug_helpers', True):
            try:
                app_helpers = app_config.package.lib.helpers
            except:
                app_helpers = None

            if app_helpers:
                setattr(app_helpers, module_name, module.helpers)

                if options.get('global_helpers', False):
                    for name, impl in inspect.getmembers(module.helpers):
                        if name.startswith('_'):
                            continue

                        if not hasattr(app_helpers, name):
                            setattr(app_helpers, name, impl)
                        else:
                            log.warning('%s helper already existing, skipping it' % name)

        if hasattr(module, 'controllers') and options.get('plug_controller', True):
            controllers_adapter = ControllersAdapter(app_config, module.controllers, options)
            app_config.register_hook('after_config', controllers_adapter.mount_controllers)

        if hasattr(module, 'bootstrap') and options.get('plug_bootstrap', True):
            websetup_adapter = WebSetupAdapter(app_config, module, options)
            websetup_adapter.adapt_bootstrap()

        if hasattr(module, 'public') and options.get('plug_statics', True):
            statics_adapter = StaticsAdapter(app_config, module, options)
            statics_adapter.register_statics(module_name, self.plugged)
Exemplo n.º 3
0
Arquivo: plug.py Projeto: mbbui/Jminee
def plug(app_config, module_name, appid=None, **kwargs):
    plugged = init_pluggables(app_config)

    if module_name in plugged['modules']:
        raise AlreadyPluggedException('Pluggable application has already been plugged for this application')

    options = dict(appid=appid)
    options.update(kwargs)
    
    module = __import__(module_name, globals(), locals(),
                        ['plugme', 'model', 'lib', 'helpers', 'controllers', 'bootstrap', 'public', 'partials'],
                        -1)

    log.info('Plugging %s', module_name)
    module_options = module.plugme(app_config, options)
    if not appid:
        appid = module_options.get('appid')

    if not appid:
        raise MissingAppIdException("Application doesn't provide a default id and none has been provided when plugging it")

    plugged['appids'][appid] = module_name
    plugged['modules'][module_name] = dict(appid=appid, module_name=module_name, module=module, statics=None)

    options['appid'] = appid

    if hasattr(module, 'model') and options.get('plug_models', True):
        models_adapter = ModelsAdapter(app_config, module.model, options)
        app_config.register_hook('startup', models_adapter.adapt_tables)
        app_config.register_hook('startup', models_adapter.init_model)

    if hasattr(module, 'helpers') and options.get('plug_helpers', True):
        try:
            app_helpers = app_config.package.lib.helpers
        except:
            app_helpers = None

        if app_helpers:
            setattr(app_helpers, module_name, module.helpers)

            if module_options.get('global_helpers', False):
                for name, impl in inspect.getmembers(module.helpers):
                    if name.startswith('_'):
                        continue

                    if not hasattr(app_helpers, name):
                        setattr(app_helpers, name, impl)
                    else:
                        log.warning('%s helper already existing, skipping it' % name)

    if hasattr(module, 'controllers') and options.get('plug_controller', True):
        controllers_adapter = ControllersAdapter(app_config, module.controllers, options)
        app_config.register_hook('after_config', controllers_adapter.mount_controllers)

    if hasattr(module, 'bootstrap') and options.get('plug_bootstrap', True):
        websetup_adapter = WebSetupAdapter(app_config, module, options)
        app_config.register_hook('startup', websetup_adapter.adapt_bootstrap)

    if hasattr(module, 'public') and options.get('plug_statics', True):
        statics_adapter = StaticsAdapter(app_config, module, options)
        statics_adapter.register_statics(module_name, plugged)