def check_existing_tables(tables, cursor): query = "select table_name from information_schema.tables where table_schema='cbpopdoxa';" cursor.execute(query) table_list = [str(x[0]).replace("u\'", '') for x in list(cursor)] if "all" in tables: if len(table_list) > 0: confirm = raw_input( "There are currently tables in the database\nType 'Y' to drop the database or press any key to skip\n" ) if confirm == "Y": kill_database() #bt.build_all_tables(cursor) bt.build_all(cursor) else: return bt.build_all(cursor) return for table in tables: if table in table_list: confirm = raw_input( table + " table already exists, Y to drop and rebuild or N to skip\n") if confirm == "Y": kill_table(table, cursor) else: tables.remove(table) tables.remove("build") return tables
def parse_args(tables): valid_tables = ['rebuild', 'build', 'all', 'states', 'users', 'votes', 'polls', 'states', 'counties', 'cities', 'clubs'] if "help" in tables: help_screen() return if "rebuild" in tables: kill_database("Yes") create_db() cnx = mysql.connector.connect(user='******', password='******', database='cbpopdoxa') bt.build_all(cnx.cursor()) cnx.commit() return if "drop" in tables and "all" in tables: kill_database() return if "build" in tables or "rebuild" in tables: for table in tables: if table not in valid_tables: print(table + " is not a valid table") print("\nValid tables: ") for table in valid_tables: if table != "rebuild" and table != "build": print table return False print("Successfully parsed input tables\n") return True else: return False
def check_existing_tables(tables, cursor): query = "select table_name from information_schema.tables where table_schema='cbpopdoxa';" cursor.execute(query) table_list = [str(x[0]).replace("u\'", '') for x in list(cursor)] if "all" in tables: if len(table_list) > 0: confirm = raw_input("There are currently tables in the database\nType 'Y' to drop the database or press any key to skip\n") if confirm == "Y": kill_database() #bt.build_all_tables(cursor) bt.build_all(cursor) else: return bt.build_all(cursor) return for table in tables: if table in table_list: confirm = raw_input(table +" table already exists, Y to drop and rebuild or N to skip\n") if confirm == "Y": kill_table(table, cursor) else: tables.remove(table) tables.remove("build") return tables
def rebuild(cursor): try: print "Trying to drop database" kill_database(cursor) except Exception as e: print e create_db(cursor) query = "use cbpopdoxa;" cursor.execute(query) bt.build_all(cursor)
def get_connec(tables, login_info): """Connect to database and calls build_tables""" try: create_db(login_info) cnx = mysql.connector.connect(user=login_info[1], password=login_info[2], database=login_info[3]) if tables == "all": bt.build_all(cnx.cursor()) else: for table in tables: if table != 'build': kill_table(table, cnx.cursor()) bt.build_tables(tables, cnx.cursor()) cnx.commit() except mysql.connector.Error as err: print(err)
def parse_args(tables): valid_tables = [ 'rebuild', 'build', 'all', 'states', 'users', 'votes', 'polls', 'states', 'counties', 'cities', 'clubs' ] if "help" in tables: help_screen() return if "rebuild" in tables: kill_database("Yes") create_db() cnx = mysql.connector.connect(user='******', password='******', database='cbpopdoxa') bt.build_all(cnx.cursor()) cnx.commit() return if "drop" in tables and "all" in tables: kill_database() return if "build" in tables or "rebuild" in tables: for table in tables: if table not in valid_tables: print(table + " is not a valid table") print("\nValid tables: ") for table in valid_tables: if table != "rebuild" and table != "build": print table return False print("Successfully parsed input tables\n") return True else: return False
def parse_args(tables, login_info): valid_tables = bt.tables.keys() if "help" in tables or len(tables) < 1: help_screen() return if "backup" in tables: cnx = mysql.connector.connect(user=login_info[1], password=login_info[2], database=login_info[3]) bu.backup_database(cnx.cursor()) return if "rebuild" in tables: create_db(login_info) kill_database("Yes", login_info) create_db(login_info) cnx = mysql.connector.connect(user=login_info[1], password=login_info[2], database=login_info[3]) bt.build_all(cnx.cursor()) cnx.commit() return if "drop" in tables and "all" in tables: kill_database("NO", login_info) return tables = tables[1:] for table in tables: if table not in valid_tables: print(table + " is not a valid table") print("\nValid tables: ") for table in valid_tables: print table return False print("Successfully parsed input tables\n") return True