示例#1
0
def setup_database(args):
    """ Setup database connection based on command line
    options.
    """
    logger = logging.getLogger('SubMit')

    if args.lite:
        use_mysql = False
        username, password = "******", "none"
        database_name = args.lite
    else:
        use_mysql = True
        if args.test_database:
            cred_file_name = '/..' + fs.test_db_cred_file  #the ../ is needed due to the path difference in client/src and utils/
            database_name = fs.MySQL_Test_DB_Name
        else:
            cred_file_name = '/..' + fs.prod_db_cred_file
            database_name = fs.MySQL_Prod_DB_Name

        cred_file_loc = os.path.dirname(
            os.path.abspath(__file__)) + cred_file_name
        cred_file = os.path.normpath(cred_file_loc)
        username, password = database.load_database_credentials(cred_file)

    logger.debug('Connecting to MySQL: {}'.format(use_mysql))

    db_conn, sql = database.get_database_connection(
        use_mysql=use_mysql,
        database_name=database_name,
        username=username,
        password=password,
        hostname=fs.db_hostname)

    return db_conn, sql
示例#2
0
def connect_to_database():
    """ Load the database login file and 
    get a read/write connection. """
    creds_file = os.path.abspath(os.path.dirname(os.path.abspath(__file__)) + '/../msqlrw.txt')
    uname, pword = load_database_credentials(creds_file)
    return get_database_connection(use_mysql=True, username=uname, password=pword,
                                   hostname='jsubmit.jlab.org', database_name="CLAS12OCR") 
示例#3
0
def connect_to_database(database_name="CLAS12TEST"):
    creds_file = os.path.abspath(
        os.path.dirname(os.path.abspath(__file__)) + '/../msqlrw.txt')
    uname, pword = load_database_credentials(creds_file)
    return get_database_connection(use_mysql=True,
                                   username=uname,
                                   password=pword,
                                   hostname='jsubmit.jlab.org',
                                   database_name=database_name)
示例#4
0
def connect_to_database(sqlite_db_name):

    creds_file = os.path.abspath(os.path.dirname(os.path.abspath(__file__)) + '/../msqlrw.txt')
    uname, pword = load_database_credentials(creds_file)

    mysql=True
    db_name="CLAS12OCR"
    if sqlite_db_name != None:
        mysql=False
        db_name = "CLAS12OCR.db"

    return get_database_connection(use_mysql=mysql, username=uname, password=pword,
                                   hostname='jsubmit.jlab.org', database_name=db_name)
示例#5
0
    else:
        use_mysql = True
        if args.test_database:
            cred_file_name = '/../msqlrw_test.txt'
            database_name = fs.MySQL_Test_DB_Name
        else:
            cred_file_name = '/../msqlrw.txt'
            database_name = fs.MySQL_Prod_DB_Name
            
        cred_file_loc = os.path.dirname(os.path.abspath(__file__)) + cred_file_name
        print("cred file loc is")
        print(cred_file_loc)
        cred_file = os.path.normpath(cred_file_loc)
        print("cred file is:")
        print(cred_file)
        username, password = database.load_database_credentials(cred_file)

    
        print("The password we have is {0}".format(password))

    db_conn, sql = database.get_database_connection(
        use_mysql=use_mysql,
        database_name=database_name,
        username=username,
        password=password,
        hostname='jsubmit.jlab.org'
    )

    # Create tables
    for table, primary_key, foreign_keys, fields in zip(
            fs.tables, fs.pks, fs.foreign_keys,
示例#6
0
Informal tests for the database.py module.  These must
be run from the utils/ folder due to the import structure.  These should be 
formalized into unittest.TestCase tests, but a test database structure
needs to be coded first. 

"""

import fs
from database import (get_database_connection, load_database_credentials,
                      get_users, select_by_user_submission_id)

if __name__ == '__main__':

    creds_file = '../msqlrw.txt'
    uname, pword = load_database_credentials(creds_file)

    db_connection, sql = get_database_connection(use_mysql=True,
                                                 hostname='jsubmit.jlab.org',
                                                 username=uname,
                                                 password=pword)

    # A simple test query
    query = """ 
    SELECT User, timestamp FROM UserSubmissions 
        WHERE UserSubmissionID > 65 AND User = '******';
    """
    sql.execute(query)
    result = sql.fetchall()
    print(result)