예제 #1
0
파일: common.py 프로젝트: ERPBlok/ERPBlok
def list_databases():
    """ return the name of the databases found in the BDD

    the result can be filtering by the Configuration entry ``db_filter``

    ..warning::

        For the moment only the ``prostgresql`` dialect is available

    :rtype: list of the database's names
    """
    url = Configuration.get_url()
    db_filter = Configuration.get('db_filter')
    text = None
    if url.drivername in ('postgres', 'postgresql'):
        url = Configuration.get_url(db_name='postgres')
        text = "SELECT datname FROM pg_database"

        if db_filter:
            db_filter = db_filter.replace('%', '%%')
            text += " where datname like '%s'" % db_filter

    if text is None:
        return []

    engine = create_engine(url)
    return [x[0] for x in engine.execute(text).fetchall()
            if x[0] not in ('template1', 'template0', 'postgres')]
예제 #2
0
 def test_get_url_without_drivername(self):
     Configuration.update(
         db_name=None,
         db_driver_name=None,
         db_host=None,
         db_user_name=None,
         db_password=None,
         db_port=None)
     with self.assertRaises(ConfigurationException):
         Configuration.get_url()
예제 #3
0
 def test_get_url2(self):
     Configuration.update(
         db_name='anyblok',
         db_driver_name='postgres',
         db_host='localhost',
         db_user_name=None,
         db_password=None,
         db_port=None,)
     url = Configuration.get_url(db_name='anyblok2')
     self.check_url(url, 'postgres://localhost/anyblok2')
예제 #4
0
 def test_get_url5(self):
     Configuration.update(
         db_url='postgres:///anyblok',
         db_name='anyblok2',
         db_driver_name=None,
         db_host=None,
         db_user_name='jssuzanne',
         db_password='******',
         db_port=None)
     url = Configuration.get_url(db_name='anyblok3')
     self.check_url(url, 'postgres://*****:*****@/anyblok3')
예제 #5
0
 def test_get_url3(self):
     Configuration.update(
         db_url='postgres:///anyblok',
         db_name=None,
         db_driver_name=None,
         db_host=None,
         db_user_name=None,
         db_password=None,
         db_port=None)
     url = Configuration.get_url()
     self.check_url(url, 'postgres:///anyblok')
예제 #6
0
파일: common.py 프로젝트: ERPBlok/ERPBlok
def drop_database(database):
    """ Close the registry instance of the database and drop the database

    :param: database's name
    """
    url = Configuration.get_url(db_name=database)
    if not database_exists(url):
        raise Exception("Database %r does not already exist")

    registry = RegistryManager.get(database)
    registry.close()
    SU_drop_database(url)
예제 #7
0
    def dropdb(cls):
        """Drop the database specified in configuration.

        ::

            cls.init_configuration_manager()
            cls.dropdb()

        """
        url = Configuration.get_url()
        if database_exists(url):
            drop_database(url)
예제 #8
0
파일: common.py 프로젝트: ERPBlok/ERPBlok
def create_database(database):
    """ Create a new database, initialize it and return an AnyBlok registry

    :param: database's name
    :rtype: AnyBlok registry instance
    """
    url = Configuration.get_url(db_name=database)
    if database_exists(url):
        raise Exception("Database %r already exist")

    db_template_name = Configuration.get('db_template_name', None)
    SU_create_database(url, template=db_template_name)
    registry = RegistryManager.get(database)
    return registry
예제 #9
0
    def createdb(cls, keep_existing=False):
        """Create the database specified in configuration.

        ::

            cls.init_configuration_manager()
            cls.createdb()

        :param keep_existing: If false drop the previous db before create it
        """
        url = Configuration.get_url()
        db_template_name = Configuration.get('db_template_name', None)
        if database_exists(url):
            if keep_existing:
                return False

            drop_database(url)

        create_database(url, template=db_template_name)
        return True