Пример #1
0
 def get_backend(self, engine):
     """ Load DATABASES[engine]['ENGINE'] directly because
         oracle can end up with oraclepool as the engine
         and your testing oraclepool speed against itself!
     """
     if engine == 'oracle':
         try:
             return load_backend('django.db.backends.oracle') 
         except: 
             # django 1.2
             return load_backend('oracle') 
     else:
         return load_backend('oraclepool')
Пример #2
0
    def db_type(self, connection):
        try:
            for backend, db_type in self.CREATION_DATA.items():
                try:
                    module = load_backend(backend)
                    DatabaseWrapper = getattr(module, 'DatabaseWrapper')
                    if isinstance(connection, DatabaseWrapper):
                        return db_type
                    elif DJANGO_VERSION >= (1, 7):
                        from django.db import (
                            DefaultConnectionProxy,
                            connections,
                        )
                        from django.db.utils import DEFAULT_DB_ALIAS
                        if (isinstance(connection, DefaultConnectionProxy) and
                           isinstance(connections[DEFAULT_DB_ALIAS],
                                      DatabaseWrapper)):

                            return db_type
                except (ImportError, exceptions.ImproperlyConfigured):
                    pass
        except (KeyError, AttributeError):
            pass
        raise exceptions.ImproperlyConfigured(
            'BigAutoField does not support the "%s" database '
            'backend' % connection.settings_dict["ENGINE"])
Пример #3
0
def getConnection(banco):
    engine = settings.SECONDARY_DB[banco]['DATABASE_ENGINE']
    if engine == "sql_server.pyodbc":
        return base.DatabaseWrapper(settings.SECONDARY_DB[banco])
    else:
        bckend = load_backend(engine)
        return bckend.DatabaseWrapper(settings.SECONDARY_DB[banco])
Пример #4
0
    def setUp(self):
        if not __django_12__:
            # Ugly but necessary
            from django.db import load_backend
            backend = load_backend('django_mongokit.mongodb')

            def get(key):
                return getattr(settings, key, None)

            self.connection = backend.DatabaseWrapper({
                'DATABASE_HOST':
                get('MONGO_DATABASE_HOST'),
                'DATABASE_NAME':
                settings.MONGO_DATABASE_NAME,
                'DATABASE_OPTIONS':
                get('MONGO_DATABASE_OPTIONS'),
                'DATABASE_PASSWORD':
                get('MONGO_DATABASE_PASSWORD'),
                'DATABASE_PORT':
                get('MONGO_DATABASE_PORT'),
                'DATABASE_USER':
                get('MONGO_DATABASE_USER'),
                'TIME_ZONE':
                settings.TIME_ZONE,
            })
            self.old_database_name = settings.MONGO_DATABASE_NAME
            self.connection.creation.create_test_db()

        db = get_database()
        assert 'test_' in db.name, db.name
Пример #5
0
    def db_type(self, connection):
        try:
            for backend, db_type in self.CREATION_DATA.items():
                try:
                    module = load_backend(backend)
                    DatabaseWrapper = getattr(module, 'DatabaseWrapper')
                    if isinstance(connection, DatabaseWrapper):
                        return db_type
                    elif DJANGO_VERSION >= (1, 7):
                        from django.db import (
                            DefaultConnectionProxy,
                            connections,
                        )
                        from django.db.utils import DEFAULT_DB_ALIAS
                        if (isinstance(connection, DefaultConnectionProxy)
                                and isinstance(connections[DEFAULT_DB_ALIAS],
                                               DatabaseWrapper)):

                            return db_type
                except (ImportError, exceptions.ImproperlyConfigured):
                    pass
        except (KeyError, AttributeError):
            pass
        raise exceptions.ImproperlyConfigured(
            'BigAutoField does not support the "%s" database '
            'backend' % connection.settings_dict["ENGINE"])
Пример #6
0
def take_snapshot(ec2_conn, vol_id, freeze_dir, lock_db=True, fs='xfs'):
    """
    Take a snapshot of the given volume, handling the freezing and unfreezing
    of the file system and locking and unlocking the db (useful for
    non-transactional databases like MyISAM mysql).
    """
    if fs != 'xfs':
        raise NotImplementedError("Support for snapshots across file systems other than xfs not currently supported")

    if lock_db:
        try:
            from django.db import load_backend

            backend = load_backend(settings.DATABASE_ENGINE)
            connection = backend.DatabaseWrapper({
                'DATABASE_HOST': settings.DATABASE_HOST,
                'DATABASE_NAME': settings.DATABASE_NAME,
                'DATABASE_OPTIONS': settings.DATABASE_OPTIONS,
                'DATABASE_PASSWORD': DATABASE_BACKUP_PASSWORD,
                'DATABASE_PORT': settings.DATABASE_PORT,
                'DATABASE_USER': DATABASE_BACKUP_USER,
                'TIME_ZONE': settings.TIME_ZONE,
            })
        except ImportError:
            # Pre Django 1.1
            backend = __import__('django.db.backends.' + settings.DATABASE_ENGINE
                + ".base", {}, {}, ['base'])
            backup = {}
            # Save the 'real' db settings so we can restore them
            prev_user = settings.DATABASE_USER
            prev_pw = settings.DATABASE_PASSWORD
            settings.DATABASE_USER = DATABASE_BACKUP_USER
            settings.DATABASE_PASSWORD = DATABASE_BACKUP_PASSWORD

            connection = backend.DatabaseWrapper()
            connection._cursor(settings)

            # Restore the db settings
            settings.DATABASE_USER = prev_user
            settings.DATABASE_PASSWORD = prev_pw

    try:
        if lock_db:
            cursor = connection.cursor()
            cursor.execute('FLUSH TABLES WITH READ LOCK;')

        # Freeze the xfs file system
        call([XFS_FREEZE_CMD, '-f', freeze_dir])

        snapshot = ec2_conn.create_snapshot(vol_id)
    finally:
        # Unfreeze the xfs file system even if our snapshot threw an error
        call([XFS_FREEZE_CMD, '-u', freeze_dir])


    logging.info("Created snapshot with id: %s" % snapshot.id)

    return snapshot.id
Пример #7
0
 def setUp(self):
     if not __django_12__:
         # Ugly but necessary
         from django.db import load_backend
         backend = load_backend('django_mongokit.mongodb')
         self.connection = backend.DatabaseWrapper({
             'DATABASE_HOST': getattr(settings, 'MONGO_DATABASE_HOST', None),
             'DATABASE_NAME': settings.MONGO_DATABASE_NAME,
             'DATABASE_OPTIONS': getattr(settings, 'MONGO_DATABASE_OPTIONS', None),
             'DATABASE_PASSWORD': getattr(settings, 'MONGO_DATABASE_PASSWORD', None),
             'DATABASE_PORT': getattr(settings, 'MONGO_DATABASE_PORT', None),
             'DATABASE_USER': getattr(settings, 'MONGO_DATABASE_USER', None),
             'TIME_ZONE': settings.TIME_ZONE,
         })
         self.old_database_name = settings.MONGO_DATABASE_NAME
         self.connection.creation.create_test_db()
             
     db = get_database()
     assert 'test_' in db.name, db.name
Пример #8
0
    def handle(self, *args, **options):
        backend = db.load_backend('mysql')
        conn = backend.DatabaseWrapper({'NAME': 'playlistpnow', 'USER': '******', 'PASSWORD': '******', 'HOST': 'localhost', 'PORT': '3306', 'OPTIONS': ''})
        old = conn.cursor()
        self.old_root_ids = (175319, 57488)

        signals.pre_save.disconnect(yourplaylist_bookmarked)
        signals.m2m_changed.disconnect(update_counts)
        signals.post_save.disconnect(new_follower, sender=Follow)
        signals.post_save.disconnect(new_follow, sender=Follow)
        signals.post_save.disconnect(playlist_create_activity, sender=Playlist)
        signals.m2m_changed.disconnect(last_playlist, sender=Playlist.tracks.through)
        signals.pre_save.disconnect(get_info_if_no_image)
        signals.m2m_changed.disconnect(update_fans)

        #self.sync_users_accounts(old)
        #self.sync_followers(old)
        #self.sync_friends(old)
        #self.sync_categories(old)
        #self.sync_tracks(old)
        self.sync_playlists(old)
Пример #9
0
def init_pool():
    if not globals().get('pool_initialized', False):
        global pool_initialized
        pool_initialized = True
        try:
            backendname = settings.DATABASES['default']['ENGINE']
            backend = load_backend(backendname)

            #replace the database object with a proxy.
            backend.Database = pool.manage(backend.Database,
                                           poolclass=pool.QueuePool,
                                           echo=settings.DEBUG,
                                           recycle=settings.DBPOOL_WAIT_TIMEOUT,
                                           pool_size=settings.DBPOOL_SIZE,
                                           max_overflow=settings.DBPOOL_MAX,
                                           timeout=settings.DBPOOL_INTERNAL_CONN_TIMEOUT)

            backend.DatabaseError = backend.Database.DatabaseError
            backend.IntegrityError = backend.Database.IntegrityError
            logging.info("Connection Pool initialized")
        except:
            logging.exception("Connection Pool initialization error")
Пример #10
0
    def _pre_setup(self):
        """Munge DB infrastructure before the superclass gets a chance to set up the DBs."""
        # clear all module state
        pindb._init_state()

        # patch up the db system to use the effective router settings (see override_settings)
        # we can't just reconstruct objects here because
        #   lots of places do from foo import baz, so they have
        #   a local reference to an object we can't replace.
        # so reach in and (gulp) mash the object's state.
        if dj_VERSION < (1, 4):
            for conn in dj_db.connections._connections.values():
                conn.close()
            dj_db.connections._connections = {}
        else:
            for conn in dj_db.connections.all():
                conn.close()
            dj_db.connections._connections = local()
        dj_db.connections.databases = settings.DATABASES

        def make_router(import_path):
            module_path, class_name = import_path.rsplit('.', 1)
            mod = importlib.import_module(module_path)
            return getattr(mod, class_name)()

        dj_db.router.routers = [
            make_router(import_path) for import_path in
            settings.DATABASE_ROUTERS]

        dj_db.connection = dj_db.connections[dj_db.DEFAULT_DB_ALIAS]
        dj_db.backend = dj_db.load_backend(dj_db.connection.settings_dict['ENGINE'])

        self.shim_runner = DjangoTestSuiteRunner()

        self.setup_databases()

        super(PinDbTestCase, self)._pre_setup()
Пример #11
0

if __django_12__:
    try:
        connection = connections['mongodb'].connection
    except ConnectionDoesNotExist:
        # Need to raise a better error
        print connections.databases
        raise
else:
    # because this is Django <1.2 doesn't load all the engines so we have to
    # do it manually.
    # Since with Django <1.2 we have to first define a normal backend engine
    # like sqlite so then the base backend for mongodb is never called
    from django.db import load_backend
    backend = load_backend('django_mongokit.mongodb')
    connection = backend.DatabaseWrapper({
        'DATABASE_HOST': getattr(settings, 'MONGO_DATABASE_HOST', None),
        'DATABASE_NAME': settings.MONGO_DATABASE_NAME,
        'DATABASE_OPTIONS': getattr(settings, 'MONGO_DATABASE_OPTIONS', None),
        'DATABASE_PASSWORD': getattr(settings, 'MONGO_DATABASE_PASSWORD',
                                     None),
        'DATABASE_PORT': getattr(settings, 'MONGO_DATABASE_PORT', None),
        'DATABASE_USER': getattr(settings, 'MONGO_DATABASE_USER', None),
        'TIME_ZONE': settings.TIME_ZONE,
    })
    connection = connection.connection


# The reason this is a function rather than an instance is that you're supposed
# to get the database object every time by calling this function. If you define
Пример #12
0
    __django_12__ = False

if __django_12__:
    try:
        connection = connections['mongodb'].connection
    except ConnectionDoesNotExist:
        # Need to raise a better error
        print connections.databases
        raise
else:
    # because this is Django <1.2 doesn't load all the engines so we have to
    # do it manually.
    # Since with Django <1.2 we have to first define a normal backend engine
    # like sqlite so then the base backend for mongodb is never called
    from django.db import load_backend
    backend = load_backend('django_mongokit.mongodb')
    connection = backend.DatabaseWrapper({
        'DATABASE_HOST':
        getattr(settings, 'MONGO_DATABASE_HOST', None),
        'DATABASE_NAME':
        settings.MONGO_DATABASE_NAME,
        'DATABASE_OPTIONS':
        getattr(settings, 'MONGO_DATABASE_OPTIONS', None),
        'DATABASE_PASSWORD':
        getattr(settings, 'MONGO_DATABASE_PASSWORD', None),
        'DATABASE_PORT':
        getattr(settings, 'MONGO_DATABASE_PORT', None),
        'DATABASE_USER':
        getattr(settings, 'MONGO_DATABASE_USER', None),
        'TIME_ZONE':
        settings.TIME_ZONE,