Ejemplo n.º 1
0
    def setup(self, app):
        for other in app.plugins:
            if not isinstance(other, SQLAlchemyPlugin): continue

            if other.keyword == self.keyword:
                raise PluginError('Found another sqlalchemy plugin with\
                    conflicting settings (non-unfque keyword).')
Ejemplo n.º 2
0
    def setup(self, app):

        for other in app.plugins:
            if not isinstance(other, JSONModelPlugin): continue
            if other.keyword == self.keyword:
                raise PluginError("Found another JSONmodel plugin with "\
                "conflicting settings (non-unique keyword).")
Ejemplo n.º 3
0
    def get_mongo(self):
        """Return the mongo connection from the environment."""
        if self.mongo_db:
            return self.mongo_db

        if len(self.uri_params['nodelist']) > 1 and MongoReplicaSetClient:
            nodes = ','.join(
                ['%s:%d' % n for n in self.uri_params['nodelist']])
            client = MongoReplicaSetClient(nodes, **self.uri_params['options'])
        else:
            client = MongoClient(self.uri_params['nodelist'][0][0],
                                 self.uri_params['nodelist'][0][1],
                                 **self.uri_params['options'])

        db = client[self.uri_params['database']]
        if self.uri_params['username']:
            if not db.authenticate(self.uri_params['username'],
                                   self.uri_params['password']):
                raise PluginError('Cannot authenticate to MongoDB for '
                                  'user: %s' % self.uri_params['username'])

        if self.post_create:
            db = self.post_create(db)

        self.mongo_db = db

        return self.mongo_db
Ejemplo n.º 4
0
    def __init__(self):
        super(Jinja2i18nPlugin, self).__init__()

        config = Config()
        self.domain = getattr(config, 'domain', 'locale')
        locale_dir = getattr(config, 'locale_dir')
        lang_code = getattr(config, 'lang_code', 'en')

        if locale_dir is None:
            locale_dir = os.path.normpath(os.path.join(
                os.path.dirname(os.path.abspath(__file__)), 'locale'))
        if not os.path.exists(locale_dir):
            raise PluginError(
                'No locale directory found, please assign a right one.')
        self.locale_dir = locale_dir
        self.lang_code = lang_code
        self.prepared = {}
        self.app = None
        self.trans = None

        self.env.add_extension('jinja2.ext.i18n')
        self.env.install_gettext_callables(
            lambda x: get_translations().ugettext(x),
            lambda s, p, n: get_translations().ungettext(s, p, n),
            newstyle=False
        )
Ejemplo n.º 5
0
 def setup(self, app):
     for other in app.plugins:
         if not isinstance(other, MetaPlugin):
             continue
         if other.keyword == self.keyword:
             raise PluginError(
                 'Found another plugin with the same keyword: {0}'.format(
                     self.keyword))
Ejemplo n.º 6
0
    def setup(self, app):
        ''' Make sure that other installed plugins don't affect the same
			keyword argument.'''
        for other in app.plugins:
            if not isinstance(other, SQLitePlugin): continue
            if other.keyword == self.keyword:
                raise PluginError("Found another sqlite plugin with "\
                "conflicting settings (non-unique keyword).")
Ejemplo n.º 7
0
 def setup(self, app):
     """Called as soon as the plugin is installed to an application."""
     for other in app.plugins:
         if not isinstance(other, ZeroDbPlugin):
             continue
         if other.keyword == self.keyword:
             raise PluginError("Found another ZeroDB plugin with "
                               "conflicting settings (non-unique keyword).")
Ejemplo n.º 8
0
 def setup(self, app):
     for other in app.plugins:
         if not isinstance(other, PikaPlugin):
             continue
         if other.keyword == self.keyword:
             raise PluginError(
                 "Found another pika plugin with conflicting settings (non-unique keyword)."
             )
Ejemplo n.º 9
0
 def setup(self, app):
     ''' Make sure that other installed plugins don't affect the same
         keyword argument.'''
     for other in app.plugins:
         if hasattr(other, "keyword"):
             if other.keyword == self.keyword:
                 raise PluginError("Found another BSONBottlePlugin plugin with "\
                 "conflicting settings (non-unique keyword).")
Ejemplo n.º 10
0
 def setup(self, app):
     ''' Make sure that other installed plugins don't affect the same keyword argument.'''
     for plugin in app.plugins:
         if not isinstance(plugin, OpenclosDbSessionPlugin):
             continue
         else:
             raise PluginError(
                 "Found another OpenclosDbSessionPlugin already installed")
Ejemplo n.º 11
0
 def setup(self, app):
     for other in app.plugins:
         if not isinstance(other, OraclePlugin):
             continue
         if other.keyword == self.keyword:
             raise PluginError(
                 'Another copy of OraclePlugin registered with same keyword: '
                 + self.keyword)
Ejemplo n.º 12
0
    def setup(self, app):
        '''Make sure plugin is only loaded once and setup DB
        '''
        for other in app.plugins:
            if isinstance(other, WtDbPlugin):
                raise PluginError('WtDbPlugin is already installed')

        # Connecting to database creates it if it doesn't exist
        self.db_connect().close()
Ejemplo n.º 13
0
 def setup(self, app):
     for other in app.plugins:
         if not isinstance(other, RedisPlugin):
             continue
         if other.keyword == self.keyword:
             raise PluginError("Found another redis plugin with "\
                     "conflicting settings (non-unique keyword).")
     if self.redisdb is None:
         self.redisdb = redis.ConnectionPool(*self.args, **self.kwargs)
Ejemplo n.º 14
0
 def setup(self, app):
     """ Make sure that other installed plugins are for different directories"""
     for other in app.plugins:
         if not isinstance(other, UCIPlugin):
             continue
         if other.config_dir == self.config_dir:
             raise PluginError("Found another uci plugin")
         if other.name == self.name:
             self.name += '_%s' % self.config_dir
Ejemplo n.º 15
0
 def setup(self, app):
     ''' Make sure that other installed plugins don't affect the same
         keyword argument.'''
     for other in app.plugins:
         if not isinstance(other, self.__class__):
             continue
         if other.keyword == self.keyword:
             raise PluginError("Found another AuthorizationHeaderBottlePlugin plugin with "
                               "conflicting settings (non-unique keyword).")
Ejemplo n.º 16
0
    def setup(self,app):
        for other in app.plugins:
            if not isinstance(other, SessionPlugin): continue
            if other.keyword == self.keyword:
                raise PluginError("Found another session plugin with "\
                        "conflicting settings (non-unique keyword).")

        if self.connection_pool is None:
            self.connection_pool = redis.ConnectionPool(host=self.host, port=self.port, db=self.db, password=self.password)
Ejemplo n.º 17
0
    def setup(self, app):
        ''' Make sure that other installed plugins don't effect the same
        keyword argument.
        '''

        for other in app.plugins:
            if not isinstance(other, IAmPyPlugin):
                continue
            if other.keyword == self.keyword:
                raise PluginError('Foud another sqlite plugin with '
                                  'conflicting settings (non-unique keyword)')
            elif other.name == self.name:
                self.name = '_' + self.keyword
    def setup(self, app):
        for other in app.plugins:
            if not isinstance(other, MongoPlugin): continue
            if other.keyword == self.keyword:
                raise PluginError("Found another redis plugin with "\
                        "conflicting settings (non-unique keyword).")

        # Remove builtin JSON Plugin
        if self.json_mongo:
            for other in app.plugins:
                if isinstance(other, JSONPlugin):
                    app.uninstall(other)
                    return
Ejemplo n.º 19
0
Archivo: lib.py Proyecto: talpah/domg
 def setup(self, app):
     """ Make sure that other installed plugins don't affect the same
     keyword argument and check if metadata is available."""
     for other in app.plugins:
         if not isinstance(other, FlashMsgPlugin):
             continue
         if other.keyword == self.keyword:
             raise PluginError("Found another flashmsg plugin "
                               "with conflicting settings ("
                               "non-unique keyword).")
     self.app = app
     self.app.add_hook('before_request', self.load_flashed)
     self.app.add_hook('after_request', self.set_flashed)
     self.app.flash = self.flash
     self.app.get_flashed_messages = self.get_flashed_messages
Ejemplo n.º 20
0
    def setup(self, app):
        """Called as soon as the plugin is installed to an application."""
        for other in app.plugins:
            if not isinstance(other, MongoPlugin):
                continue
            if other.keyword == self.keyword:
                raise PluginError("Found another MongoDB plugin with "
                                  "conflicting settings (non-unique keyword).")

        # Remove builtin JSON Plugin
        if self.json_mongo:
            for other in app.plugins:
                if isinstance(other, JSONPlugin):
                    app.uninstall(other)
                    return
Ejemplo n.º 21
0
    def __init__(self,
                 domain,
                 locale_dir,
                 lang_code=None,
                 default='en',
                 keyword='i18n'):
        self.domain = domain
        if locale_dir is None:
            raise PluginError(
                'No locale directory found, please assign a right one.')
        self._locale_dir = locale_dir

        self._locales = self._get_languages(self._locale_dir)
        self._default = default
        self._lang_code = lang_code

        self._cache = {}
        self._apps = []
        self._keyword = keyword
Ejemplo n.º 22
0
    def setup(self, app):
        '''Make sure plugin is only loaded once and setup CORS
        '''
        for other in app.plugins:
            if isinstance(other, WtCorsPlugin):
                raise PluginError('WtCorsPlugin is already installed')

        # Add hook to insert headers
        app.add_hook('after_request', self.prepare_cors_headers())

        # Add OPTIONS routes for each existing route
        for r in list(app.routes):
            if r.method in self.preflight_methods:
                # Store method for this rule
                self.methods.setdefault(r.rule, []).append(r.method)

                # Create a new OPTIONS route for the same rule
                options_route = copy.copy(r)
                options_route.method = 'OPTIONS'
                options_route.callback = self.prepare_preflight_route(
                    self.methods[r.rule])
                options_route.reset()
                r.app.add_route(options_route)
Ejemplo n.º 23
0
 def setup(self, app):
     for other in app.plugins:
         if not isinstance(other, ParseArgs): continue
         if other.name == self.name:
             raise PluginError("conflicting plugin")
Ejemplo n.º 24
0
 def setup(self, app):
     for other in app.plugins:
         if isinstance(other, BasicAuthPlugin):
             raise PluginError('Another BasicAuthPlugin is installed')