def switch_active_database(self, dbname):
        try:  # open the wordpress config file
            with open(self.config_file_location, 'r') as wp_config:
                file_contents = wp_config.read()
            wp_config.close()

            # Comment out all uncommented db
            uncommentedDB = r'([^\/\/])define\(\'DB_NAME\''
            commentedDB = r"\1//define('DB_NAME'"
            file_contents = re.sub(uncommentedDB,
                                   commentedDB,
                                   file_contents)

            # Un-comment our our chosen database
            commentedDB = r'\/\/define\(\'DB_NAME\',\s+\'%s\'' % dbname
            uncommentedDB = "define('DB_NAME', '%s'" % dbname
            file_contents = re.sub(commentedDB,
                                   uncommentedDB,
                                   file_contents)

            # Overwrite the config file with our new config
            with open(self.config_file_location, 'w') as wp_config:
                wp_config.write(file_contents)
            wp_config.close()
            message = "Switched database to %s" % dbname
            sublime.status_message(message)
        except __HOLE__:  # Couldn't open config file, alert user
            sublime.status_message("wp-config file doesn't exist, " +
                                   'check your settings')
dataset/ETHPy150Open huntlyc/Sublime-Wordpress-Dev-Plugin/wordpress_dev.py/WordpressDbSwitcherCommand.switch_active_database