Ejemplo n.º 1
0
def connectToNlpdev(api='adodbapi'):
    '''
    Function: connectToNlpdev
    Input:
        api - which odbc api to use. originally we only used adodbapi but had
              problems with that on VMs so added pyodbc, which seems to work
              better but I didn't want to chance breaking all the old stuff
    Output: cnctn - connection to NLPdev database on ghriNLP server
    Functionality: Creates a connection to NLPdev on ghriNLP
    History:
        12/30/10 - created
        7/13/11 - added api input and modified to use pyodbc as well
        7/27/11 - added warning logging message for using adodbapi from some
                  machines at GHRI
    '''

    if api == 'adodbapi':
        logging.warning('Using adodbapi to connect to Nlpdev may not work ' + \
                        'on some machines, including GHRI VMs')
        # make connection with adodbapi
        cnctn = connect('Data Source=ghriNLP;Initial Catalog=NLPdev;' + \
                        'Trusted_Connection=true;')
    elif api == 'pyodbc':
        # make connection with pyodbc
        cnctn = pyoconnect('DSN=ghriNLP;DATABASE=NLPdev;')
    else:
        logging.warning('Unrecognized api, using pyodbc')

        # make connection with pyodbc
        cnctn = pyoconnect('DSN=ghriNLP;DATABASE=NLPdev;')

    return cnctn            # return output
Ejemplo n.º 2
0
def connectToNewClarity(api='pyodbc'):
    '''
    Function: connectToNewClarity
    Input:
        api - which odbc api to use. we never used adodbapi with this database,
              which is why the default here is pyodbc
    Output: cnctn - connection to the new Clarity database.
    Functionality: Creates a connection to the new Clarity reporting database
                   where "new" means after the changes rolled out in November,
                   2010
    History:
        7/11/11 - Created
        7/13/11 - Removed whichdb input and decided to make two mtehods,
                  renaming this from connectToClarity and I will create
                  connectToOldClarity, too
    '''
    logging.debug('entering connectToNewClarity with api %s'%(api))

    if api == 'pyodbc':
        # make connection with pyodbc
        logging.debug('pre pyoconnect')
        try:
            cnctn = pyoconnect('DSN=epclarity_rpt;DATABASE=Clarity;')
        except Exception as myerr:
            logging.error('myerr: %s'%(str(myerr)))
            raise
        logging.debug('post pyoconnect')
    elif api == 'adodbapi':
        # make connection with adodbapi. I don't think i've every been able
        # to connect to New Clarity with this api, or maybe it's just on the
        # VM I've had trouble...
        logging.warning('Connecting to Clarity with adodbapi untested.')
        try:
            cnctn = connect('Data Source=epclarity_rpt;' + \
                            'Initial Catalog=Clarity;')
        except Exception as myerr:
            if not myerr:
                logging.error('myerr is None')
            logging.error('myerr: %s'%(str(myerr)))
            raise
        logging.debug('post connect with adodbapi')
    else:
        logging.warning('Unrecognized api, using pyodbc')

        # make connection with pyodbc
        cnctn = pyoconnect('DSN=epclarity_rpt;DATABASE=Clarity;')

                    # not sure why, but this part doesn't work with this driver
                    #'Trusted_Connection=true;')

    return cnctn            # return output
Ejemplo n.º 3
0
def connectToNoNo(api='pyodbc'):
    '''
    Date: 7/20/11
    Input:
        api - which odbc api to use. we never used adodbapi with this database,
              which is why the default here is pyodbc
    Output: cnctn - connection to the ChsDwNoContact database on the ctrhs-sql2k
                    server, not to be confused with the ctrhs-sql2k\sql2k server
    Functionality: Creates a connection to the ChsDwNoContact database on the
                   ctrhs-sql2k server (not to be confused with the
                   ctrhs-sql2k\sql2k server), which is where the Nono and
                   Nochartreview lists are stored in sql.
    '''
    if api == 'pyodbc':
        # make connection with pyodbc
        try:
            # TODO: modularize this stuff
            cnctn = pyoconnect('DSN=CTRHS-SQL2K;DATABASE=ChsDwNoContact;')
        except Exception as myerr:
            logging.error('myerr: %s'%(str(myerr)))
            raise
    elif api == 'adodbapi':
        # make connection with adodbapi. untested
        logging.warning('Connecting to nono with adodbapi untested.')
        try:
            cnctn = connect('Data Source=CTRHS-SQL2K;' + \
                            'Initial Catalog=ChsDwNoContact;')
        except Exception as myerr:
            if not myerr:
                logging.error('myerr is None')
            logging.error('myerr: %s'%(str(myerr)))
            raise
    else:
        logging.warning('Unrecognized api, using pyodbc')

        # make connection with pyodbc
        cnctn = pyoconnect('DSN=CTRHS-SQL2K;DATABASE=ChsDwNoContact;')

    return cnctn            # return output