(self, db_resource)
return output
remove a postgres database . Note this is a very dangerous
        operation.  Use with care.
remove a postgres database . Note this is a very dangerous
        operation.  Use with care.
remove a postgres database . Note this is a very dangerous operation . Use with care .
def drop_database(self, db_resource):
        '''remove a postgres database . Note this is a very dangerous
        operation.  Use with care.'''


        # if the database already exists, do nothing
        if not self.database_exists(db_resource):
            return
        from .sql import DbResource, DbContainer, Sql

        if isinstance(db_resource, DbResource):
            database = db_resource.get_database()
        else:
            database = db_resource
        info = self._get_db_info(db_resource)

        database_version = Sql.get_default_database_version()
        major = database_version[0]
        minor = database_version[1]


        # connect from the main db
        sql = DbContainer.get('sthpw')

        # try to kill the connections first
        version = '%s.%s' %(major, minor)
        if version >= '8.4':
            col_name = 'procpid'
            if version >= '9.2':
                col_name = 'pid'


            sql.do_query("""SELECT pg_terminate_backend(pg_stat_activity.%s)
            FROM pg_stat_activity WHERE pg_stat_activity.datname = '%s'"""%(col_name, database))

        print("Dropping Database [%s] ..." % database)
        """
        isolation_level = sql.conn.isolation_level
        sql.conn.set_isolation_level(0)
        sql.execute('''DROP DATABASE "%s";''' % str(database) )
        # FIXME: this creates a warning
        DbContainer.release_thread_sql()
        """

        # use PGPASSWORD environment variable to prevent dropdb from interactively asking for a password
        os.environ['PGPASSWORD'] = db_resource.get_password()

        cmds = ['dropdb']
        cmds.extend(info.split(' '))
        # has to str() to avoid unicode str
        cmds.append(str(database))

        #drop_cmd = "dropdb %s %s" % (info, database)
        #cmd = os.popen(drop_cmd, 'r')
        #result = cmd.readlines()
        #cmd.close()
        popen = subprocess.Popen(cmds, shell=False, stdout=subprocess.PIPE)
        popen.wait()
        output = ''
        value = popen.communicate()
        if value:
            output = value[0].strip()
            if not output:
                err = value[1]
                if err:
                    output = err

        return output
def drop_database ( self , db_resource ) : # if the database already exists, do nothing if not self . database_exists ( db_resource ) : return from . sql import DbResource , DbContainer , Sql if isinstance ( db_resource , DbResource ) : database = db_resource . get_database ( ) else : database = db_resource info = self . _get_db_info ( db_resource ) database_version = Sql . get_default_database_version ( ) major = database_version [ 0 ] minor = database_version [ 1 ] # connect from the main db sql = DbContainer . get ( 'sthpw' ) # try to kill the connections first version = '%s.%s' % ( major , minor ) if version >= '8.4' : col_name = 'procpid' if version >= '9.2' : col_name = 'pid' sql . do_query ( """SELECT pg_terminate_backend(pg_stat_activity.%s)
            FROM pg_stat_activity WHERE pg_stat_activity.datname = '%s'""" % ( col_name , database ) ) print ( "Dropping Database [%s] ..." % database ) """
        isolation_level = sql.conn.isolation_level
        sql.conn.set_isolation_level(0)
        sql.execute('''DROP DATABASE "%s";''' % str(database) )
        # FIXME: this creates a warning
        DbContainer.release_thread_sql()
        """ # use PGPASSWORD environment variable to prevent dropdb from interactively asking for a password os . environ [ 'PGPASSWORD' ] = db_resource . get_password ( ) cmds = [ 'dropdb' ] cmds . extend ( info . split ( ' ' ) ) # has to str() to avoid unicode str cmds . append ( str ( database ) ) #drop_cmd = "dropdb %s %s" % (info, database) #cmd = os.popen(drop_cmd, 'r') #result = cmd.readlines() #cmd.close() popen = subprocess . Popen ( cmds , shell = False , stdout = subprocess . PIPE ) popen . wait ( ) output = '' value = popen . communicate ( ) if value : output = value [ 0 ] . strip ( ) if not output : err = value [ 1 ] if err : output = err return output