Example #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)