<commit_before>"""
Copyright [2009-2017] EMBL-European Bioinformatics Institute
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
     http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

'''
TO DO: Need to generalize this to make the scripts independent and enable
       connecting to multiple databases simultaneously. Convert this to a class
'''

# ---------------------------------IMPORTS-------------------------------------
import mysql.connector
from mysql.connector import errorcode

from config.rfam_config import RFAMLIVEPUB  # rfam_live on public host
from config.rfam_config import RFAMLIVE  # rfam_live on curation host
from config.rfam_config import RFAMLIVELOC  # local instance of rfam_live
from config.rfam_config import XFAMDEV

# -----------------------------------------------------------------------------
# need to generalize this to enable DB setting upon implementation 
db_conf = XFAMDEV

# -----------------------------------------------------------------------------


def connect():
    """
    Connects to a specific database and returns a mysql connection object
    """

    try:
        cnx = mysql.connector.connect(user=db_conf["user"],
                                      password=db_conf["<PASSWORD>"],
                                      host=db_conf["host"],
                                      database=db_conf["db"],
                                      port=db_conf["port"])

    except mysql.connector.Error as err:

        if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
            print "Wrong username or password"

        elif err.errno == errorcode.ER_BAD_DB_ERROR:
            print "Database does not exist"

        else:
            print err<commit_msg>Initialization of cnx variable to increase local scope<commit_after>"""
Copyright [2009-2017] EMBL-European Bioinformatics Institute
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
     http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

'''
TO DO: Need to generalize this to make the scripts independent and enable
       connecting to multiple databases simultaneously. Convert this to a class
'''

# ---------------------------------IMPORTS-------------------------------------
import mysql.connector
from mysql.connector import errorcode

from config.rfam_config import RFAMLIVEPUB  # rfam_live on public host
from config.rfam_config import RFAMLIVE  # rfam_live on curation host
from config.rfam_config import RFAMLIVELOC  # local instance of rfam_live
#from config.rfam_config import XFAMDEV

# -----------------------------------------------------------------------------
# need to generalize this to enable DB setting upon implementation 
db_conf = RFAMLIVE

# -----------------------------------------------------------------------------


def connect():
    """
    Connects to a specific database and returns a mysql connection object
    """

    cnx=None
    try:
        cnx = mysql.connector.connect(user=db_conf["user"],
                                      password=db_conf["pwd"],
                                      host=db_conf["host"],
                                      database=db_conf["db"],
                                      port=db_conf["port"])

    except mysql.connector.Error as err:

        if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
            print "Wrong username or password"

        elif err.errno == errorcode.ER_BAD_DB_ERROR:
            print "Database does not exist"

        else:
            print err
{'fraction_non_alphanumeric': 0.16046242774566474, 'fraction_numerical': 0.0055491329479768784, 'mean_word_length': 1.9170600134861766, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2306542', 'n_tokens_mistral': 1043, 'n_tokens_neox': 981, 'n_words': 401}