Exemplo n.º 1
0
def loadDemoTables():
    '''
       Load the tables used in the Demo, if they don't exist. 
    '''
    dbconn = DBConnect()
    conn_dict = dbconn.getConnectionString()

    load_tbl_stmt = '''psql -h {hostname} -p {port}  -U {username}  -d {database} -f '''
    load_tbl_stmt = load_tbl_stmt.format(username=conn_dict['username'],
                                         hostname=conn_dict['hostname'],
                                         database=conn_dict['database'],
                                         port=conn_dict['port'])

    this_dir = os.path.dirname(os.path.abspath(__file__))

    for fl in os.listdir(os.path.join(this_dir, 'data/')):
        full_path = os.path.join(os.path.join(this_dir, 'data'), fl)
        if (fl.endswith('.sql')):
            #If the demo table does not exists in the database already, create it using the provided sql files
            if (not __isTableExists__(fl[:-len('.sql')], dbconn)):
                logging.info('cmd:{0}'.format(load_tbl_stmt + ' ' + full_path))
                cmd = load_tbl_stmt + ' ' + full_path
                os.system(cmd)

    logging.info('Loading demo tables complete')
Exemplo n.º 2
0
def loadDemoTables():
    '''
       Load the tables used in the Demo, if they don't exist. 
    '''
    dbconn = DBConnect()
    conn_dict = dbconn.getConnectionString()
    
    load_tbl_stmt = '''psql -h {hostname} -p {port}  -U {username}  -d {database} -f '''
    load_tbl_stmt = load_tbl_stmt.format( username=conn_dict['username'],
                                          hostname=conn_dict['hostname'],
                                          database=conn_dict['database'],
                                          port=conn_dict['port']
                                        )
    
    this_dir = os.path.dirname(os.path.abspath(__file__))

    for fl in os.listdir(os.path.join(this_dir,'data/')):
        full_path = os.path.join(os.path.join(this_dir,'data'),fl)
        if(fl.endswith('.sql')):
            #If the demo table does not exists in the database already, create it using the provided sql files
            if(not __isTableExists__(fl[:-len('.sql')],dbconn)):   
                logging.info('cmd:{0}'.format(load_tbl_stmt+' '+full_path))
                cmd = load_tbl_stmt+ ' '+full_path
                os.system(cmd)         
                
    logging.info('Loading demo tables complete')